You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Note: I originally opened this as bug report, but since found some workarounds. This is now likely more of a general question or a feature request.
I'm attempting to implement a custom auth passwordless flow where the user signs in using a 6-digit code emailed to them.
It's largely based off this example from the docs. I'm using AWSMobileClient, not Amplify. This is within an iOS app.
The current problem is providing a single-flow sign in where if an account exists, the user is signed in, otherwise an account is created and then signed in. Unfortunately, this isn't the default behavior.
To handle this, I set up a PreSignUpTriggerHandler that uses listUsers to check if the account exists - if it does exist, do not allow the sign up. If it doesn't exist, allow the sign up.
How can I modify the pre-sign up handler so if the account does exist, it does not allow the sign up but jumps into the sign in flow? That way, I could always call AWSMobileClient.signUp() and handle it accordingly on the server.
import{CognitoIdentityProviderClient,ListUsersCommand,ListUsersCommandInput,ListUsersCommandOutput}from'@aws-sdk/client-cognito-identity-provider'import{PreSignUpTriggerEvent,PreSignUpTriggerHandler}from'aws-lambda'exportconsthandler: PreSignUpTriggerHandler=async(event: PreSignUpTriggerEvent)=>{console.log('preSignUp event.request: ',JSON.stringify(event.request,null,2))constemail=event.request.userAttributes.emailif(!email){thrownewError("Email attribute is required.")}constinput: ListUsersCommandInput={UserPoolId: 'us-east-2_xxxxxx',Filter: `email = \"${email}\"`}try{constclient=newCognitoIdentityProviderClient()constcommand=newListUsersCommand(input)constresponse: ListUsersCommandOutput=awaitclient.send(command)if(typeofresponse.Users!=='undefined'&&response.Users.length>0){// TODO: How to sign in the user instead?console.log("User with this email already exists.")thrownewError("Email already registered.")}else{console.log("User not found, allowing sign-up.")event.response.autoConfirmUser=truereturnevent}}catch(error){console.error("Error in PreSignUp Lambda: ",error)thrownewError("Error checking email existence.")}}
To Reproduce
Steps to reproduce the behavior:
See the above explanation please.
Observed Behavior
The email attribute is not available in the event sent to the Lambda trigger.
Expected Behavior
The email attribute should be present.
Stack Trace
There is no stack trace specifically related to this. The Lambda will crash when attempting to send an email, but that is because email is undefined, so the stack trace is not directly relevant to the issue, but rather a side-effect.
Code Snippet
See the above explanation please.
Unique Configuration
If you are reporting an issue with a unique configuration or where configuration can make a difference in code execution (i.e. Cognito) please provide your configuration. Please make sure to obfuscate sensitive information from the configuration before posting.
Areas of the SDK you are using (AWSMobileClient, Cognito, Pinpoint, IoT, etc)?
AWSMobileClient, Cognito
Screenshots
N/A
Environment(please complete the following information):
ghost
changed the title
AWSMobileClient custom passwordless email auth - email is missing from user attributes
AWSMobileClient Cognito custom passwordless email auth - email is missing from user attributes
Sep 13, 2024
ghost
changed the title
AWSMobileClient Cognito custom passwordless email auth - email is missing from user attributes
AWSMobileClient Cognito custom passwordless email auth - escape hatch from PreSignUpTriggerHandler to sign in flow
Sep 13, 2024
This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.
Describe the bug
Note: I originally opened this as bug report, but since found some workarounds. This is now likely more of a general question or a feature request.
I'm attempting to implement a custom auth passwordless flow where the user signs in using a 6-digit code emailed to them.
It's largely based off this example from the docs. I'm using
AWSMobileClient
, not Amplify. This is within an iOS app.The current problem is providing a single-flow sign in where if an account exists, the user is signed in, otherwise an account is created and then signed in. Unfortunately, this isn't the default behavior.
To handle this, I set up a
PreSignUpTriggerHandler
that useslistUsers
to check if the account exists - if it does exist, do not allow the sign up. If it doesn't exist, allow the sign up.How can I modify the pre-sign up handler so if the account does exist, it does not allow the sign up but jumps into the sign in flow? That way, I could always call
AWSMobileClient.signUp()
and handle it accordingly on the server.The Cognito stack:
The
preSignUp
Lambda:To Reproduce
Steps to reproduce the behavior:
See the above explanation please.
Observed Behavior
The email attribute is not available in the event sent to the Lambda trigger.
Expected Behavior
The email attribute should be present.
Stack Trace
There is no stack trace specifically related to this. The Lambda will crash when attempting to send an email, but that is because email is undefined, so the stack trace is not directly relevant to the issue, but rather a side-effect.
Code Snippet
See the above explanation please.
Unique Configuration
If you are reporting an issue with a unique configuration or where configuration can make a difference in code execution (i.e. Cognito) please provide your configuration. Please make sure to obfuscate sensitive information from the configuration before posting.
Areas of the SDK you are using (AWSMobileClient, Cognito, Pinpoint, IoT, etc)?
AWSMobileClient, Cognito
Screenshots
N/A
Environment(please complete the following information):
Device Information (please complete the following information):
Additional context
N/A
Relevant Console Output
N/A
Logs
N/A
The text was updated successfully, but these errors were encountered: