Skip to content

Commit

Permalink
Fix/usernotfound (#214)
Browse files Browse the repository at this point in the history
  • Loading branch information
ottokruse authored Nov 21, 2024
1 parent e11af28 commit b537544
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cdk/custom-auth/magic-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ export async function addChallengeToEvent(
await createAndSendMagicLink(event, {
redirectUri,
});
const email = event.request.userAttributes.email;
// The event.request.userNotFound is only present in the Lambda trigger if "Prevent user existence errors" is checked
// in the Cognito app client. If it is *not* checked, the client receives the error, which potentially allows for
// user enumeration. Additional guardrails are advisable.
Expand All @@ -136,7 +135,7 @@ export async function addChallengeToEvent(
// if you want to use them in your front-end:
// event.response.publicChallengeParameters = {};
event.response.privateChallengeParameters = {
email: email,
challenge: "PROVIDE_MAGIC_LINK", // doesn't matter what this is, as long as there is *something* in the privateChallengeParameters
};
}

Expand Down Expand Up @@ -285,6 +284,8 @@ async function createAndSendMagicLink(
logger.debug("Sending magic link ...");
// Toggle userNotFound error with "Prevent user existence errors" in the Cognito app client. (see above)
if (event.request.userNotFound) {
logger.debug("Pretending to send magic link ...");
await new Promise((resolve) => setTimeout(resolve, Math.random() * 200));
return;
}
await config.emailSender({
Expand Down

0 comments on commit b537544

Please sign in to comment.