I am unable to know how to do passwordless signin with OTP using cognito in flutter. I just need assistance with the flutter code for sending the OTP and answering the auth challenger with any working cognito/amplify package.
1 Answer
I was able to do with this package: amazon_cognito_identity_dart_2
//Create a cognito user
CognitoUser cognitoUser1;
//Send OTP
cognitoUser1 = CognitoUser(phoneNumber.text, widget.userPool);
try {
CognitoUserSession cognitoUserSession =
await cognitoUser1.initiateAuth(
AuthenticationDetails(
authParameters: [
AttributeArg(
name: 'phone_number',
value: phoneNumber.text,
),
],
),
);
} catch (cognitoUserCustomChallengeException) {}
//Authenticate the user
CognitoUserSession cognitoUserSession = await cognitoUser1.sendCustomChallengeAnswer(otp.text);
print("jwtToken " + cognitoUserSession.accessToken.jwtToken);
print("refreshToken " + cognitoUserSession.refreshToken.token);
-
Can you show more of the code pls or a bit more explanation because I'm stuck on the same issue and don't know how to approach it Mar 31, 2022 at 8:57