How do I get user input values in the Create Auth challenge lambda for login?


I am using AWS cognito lambda triggers for user sign-in. Users can sign in to their mobile number as well as their email, based on the OTP. I configured lambda triggers as

1- pre signup  2-create auth challenge  3-define auth challenge 4-verify auth challenge

In the create auth challenge lambda, an OTP was sent to the user's mobile number or email as the user had given it.

My problem was that the user signed in successfully, but the user inputted the login page and did not know what the user input value was. How do I get that user input value, like a mobile number or email, in the custom create auth challenge lambda?

This is the amplify React app sig-in function.

Enter image description here

1 Answer
Accepted Answer

In AWS Cognito Lambda triggers, the create auth challenge trigger does not have direct access to the user input values (such as mobile number or email) provided during sign-in. However, you can include this information in the challenge parameters when you create the authentication challenge.

First, capture the user input (email or mobile number) and store it in a DynamoDB table or another storage associated with the user.

Then create Auth Challenge Trigger to retrieve the user input from the storage based on the user's unique identifier (e.g., Cognito username) and include it in the challenge parameters. This way, the information will be available during the challenge.

You can modify your code, so that the signIn function now takes a username parameter instead of a number, and if there's a UsernameExistsException, it recursively calls itself with the same username. This ensures that the correct username is used throughout the sign-in process.




answered 6 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions