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

0

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개 답변
0
수락된 답변

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.

Reference:

[1]. https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-pre-sign-up.html#aws-lambda-triggers-pre-registration-example

[2]. https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-create-auth-challenge.html#aws-lambda-triggers-create-auth-challenge-example

AWS
Srinath
답변함 6달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인