cognito-local
Advanced tools
Comparing version 4.1.0 to 5.0.0
@@ -78,12 +78,18 @@ var __create = Object.create; | ||
} | ||
const attributes = (0, import_userPoolService.attributesInclude)("sub", req.UserAttributes) ? req.UserAttributes ?? [] : [{ Name: "sub", Value: uuid.v4() }, ...req.UserAttributes ?? []]; | ||
const sub = uuid.v4(); | ||
const attributes = (0, import_userPoolService.attributesInclude)("sub", req.UserAttributes) ? req.UserAttributes ?? [] : [{ Name: "sub", Value: sub }, ...req.UserAttributes ?? []]; | ||
const now = clock.get(); | ||
const temporaryPassword = req.TemporaryPassword ?? process.env.CODE ?? generator.new().slice(0, 6); | ||
const isEmailUsername = (_a = config.UserPoolDefaults.UsernameAttributes) == null ? void 0 : _a.includes("email"); | ||
const hasEmailAttribute = (0, import_userPoolService.attributesInclude)("email", attributes); | ||
if (isEmailUsername && !hasEmailAttribute) { | ||
attributes.push({ Name: "email", Value: req.Username }); | ||
let username = req.Username; | ||
if ((_a = userPool.options.UsernameAttributes) == null ? void 0 : _a.includes("email")) { | ||
if (!req.Username.includes("@")) { | ||
throw new import_errors.InvalidParameterError("Username should be an email."); | ||
} | ||
if (!(0, import_userPoolService.attributesInclude)("email", attributes)) { | ||
attributes.push({ Name: "email", Value: req.Username }); | ||
} | ||
username = sub; | ||
} | ||
const user = { | ||
Username: req.Username, | ||
Username: username, | ||
Password: temporaryPassword, | ||
@@ -90,0 +96,0 @@ Attributes: attributes, |
@@ -66,3 +66,3 @@ var __create = Object.create; | ||
}) => async (ctx, req) => { | ||
var _a; | ||
var _a, _b; | ||
const userPool = await cognito.getUserPoolForClientId(ctx, req.ClientId); | ||
@@ -73,4 +73,15 @@ const existingUser = await userPool.getUserByUsername(ctx, req.Username); | ||
} | ||
const attributes = (0, import_userPoolService.attributesInclude)("sub", req.UserAttributes) ? req.UserAttributes ?? [] : [{ Name: "sub", Value: uuid.v4() }, ...req.UserAttributes ?? []]; | ||
const sub = uuid.v4(); | ||
const attributes = ((0, import_userPoolService.attributesInclude)("sub", req.UserAttributes) ? req.UserAttributes : [{ Name: "sub", Value: sub }, ...req.UserAttributes ?? []]) ?? []; | ||
let userStatus = "UNCONFIRMED"; | ||
let username = req.Username; | ||
if ((_a = userPool.options.UsernameAttributes) == null ? void 0 : _a.includes("email")) { | ||
if (!req.Username.includes("@")) { | ||
throw new import_errors.InvalidParameterError("Username should be an email."); | ||
} | ||
if (!(0, import_userPoolService.attributesInclude)("email", attributes)) { | ||
attributes.push({ Name: "email", Value: req.Username }); | ||
} | ||
username = sub; | ||
} | ||
if (triggers.enabled("PreSignUp")) { | ||
@@ -82,3 +93,3 @@ const { autoConfirmUser, autoVerifyEmail, autoVerifyPhone } = await triggers.preSignUp(ctx, { | ||
userAttributes: attributes, | ||
username: req.Username, | ||
username, | ||
userPoolId: userPool.options.Id, | ||
@@ -90,3 +101,3 @@ validationData: void 0 | ||
} | ||
const isEmailUsername = (_a = config.UserPoolDefaults.UsernameAttributes) == null ? void 0 : _a.includes("email"); | ||
const isEmailUsername = (_b = config.UserPoolDefaults.UsernameAttributes) == null ? void 0 : _b.includes("email"); | ||
const hasEmailAttribute = (0, import_userPoolService.attributesInclude)("email", attributes); | ||
@@ -111,3 +122,3 @@ if (isEmailUsername && !hasEmailAttribute) { | ||
UserLastModifiedDate: now, | ||
Username: req.Username, | ||
Username: username, | ||
UserStatus: userStatus | ||
@@ -125,3 +136,3 @@ }; | ||
source: "PostConfirmation_ConfirmSignUp", | ||
username: updatedUser.Username, | ||
username, | ||
userPoolId: userPool.options.Id, | ||
@@ -134,3 +145,3 @@ userAttributes: (0, import_userPoolService.attributesAppend)(updatedUser.Attributes, (0, import_userPoolService.attribute)("cognito:user_status", updatedUser.UserStatus)) | ||
UserConfirmed: updatedUser.UserStatus === "CONFIRMED", | ||
UserSub: (0, import_userPoolService.attributeValue)("sub", updatedUser.Attributes) | ||
UserSub: sub | ||
}; | ||
@@ -137,0 +148,0 @@ }; |
{ | ||
"name": "cognito-local", | ||
"version": "4.1.0", | ||
"version": "5.0.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "bin": "lib/bin/start.js", |
384249
7691