From 2c823f0fe08c9d74754857f2433044d401ddb683 Mon Sep 17 00:00:00 2001 From: Paul L'Allier Date: Thu, 24 Nov 2022 10:27:05 +0000 Subject: [PATCH 1/2] feat(confirmationCodes): add CODE environment variable to pre-define the confirmation codes --- src/services/otp.ts | 1 + src/targets/adminCreateUser.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/services/otp.ts b/src/services/otp.ts index 9c7af29f..860db5f3 100644 --- a/src/services/otp.ts +++ b/src/services/otp.ts @@ -1,4 +1,5 @@ export const otp = (): string => + process.env.CODE ?? Math.floor(Math.random() * 999999) .toString() .padStart(6, "0"); diff --git a/src/targets/adminCreateUser.ts b/src/targets/adminCreateUser.ts index a0acd2eb..08266b2e 100644 --- a/src/targets/adminCreateUser.ts +++ b/src/targets/adminCreateUser.ts @@ -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"); From 9143469744a9eab86ac40e372e0be21992d1c503 Mon Sep 17 00:00:00 2001 From: Paul L'Allier Date: Thu, 24 Nov 2022 10:32:06 +0000 Subject: [PATCH 2/2] feat(confirmationCodes): update README file --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 19ab63f9..82b07a11 100644 --- a/README.md +++ b/README.md @@ -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