Skip to content

Commit

Permalink
Merge pull request #340 from paullallier/conf_code_predef_feat
Browse files Browse the repository at this point in the history
feat(confirmationCodes): add CODE environment variable to pre-define code
  • Loading branch information
jagregory authored Mar 10, 2023
2 parents afb5bfd + 9143469 commit c4fabd5
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,8 @@ For example:

If a Custom Message lambda is configured, the output of the function invocation will be printed in the console too (verbosely!).

By default, confirmation codes are randomly generated. If set, the value assigned to the `CODE` environment variable will always be returned instead.

## Advanced

### Debugging Cognito Local
Expand Down
1 change: 1 addition & 0 deletions src/services/otp.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const otp = (): string =>
process.env.CODE ??
Math.floor(Math.random() * 999999)
.toString()
.padStart(6, "0");
2 changes: 1 addition & 1 deletion src/targets/adminCreateUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export const AdminCreateUser =
const now = clock.get();

const temporaryPassword =
req.TemporaryPassword ?? generator.new().slice(0, 6);
req.TemporaryPassword ?? process.env.CODE ?? generator.new().slice(0, 6);

const isEmailUsername =
config.UserPoolDefaults.UsernameAttributes?.includes("email");
Expand Down

0 comments on commit c4fabd5

Please sign in to comment.