Page updated Nov 14, 2023

Multi-step sign-in

After a user has finished signup, they can proceed to sign in. Amplify Auth signin flows can be multi step processes. The required steps are determined by the configuration you provided when you ran amplify add auth. Depending on the configuration, you may need to call various APIs to finish authenticating a user's signin attempt. To identify the next step in a signin flow, inspect the nextStep parameter in the signin result.

New enumeration values

When Amplify adds a new enumeration value (e.g., a new enum class entry or sealed class subtype in Kotlin, or a new enum value in Swift/Dart/Kotlin), it will publish a new minor version of the Amplify Library. Plugins that switch over enumeration values should include default handlers (an else branch in Kotlin or a default statement in Swift/Dart/Kotlin) to ensure that they are not impacted by new enumeration values.

When called successfully, the signin APIs will return an AuthSignInResult. Inspect the nextStep property in the result to see if additional signin steps are required. The nextStep property is of enum type AuthSignInStep. Depending on its value, your code should take one of the following actions:

1try {
2 AWSCognitoAuthSignInOptions options = AWSCognitoAuthSignInOptions.builder().authFlowType(AuthFlowType.USER_SRP_AUTH).build();
3 Amplify.Auth.signIn(
4 "username",
5 "password",
6 options,
7 result ->
8 {
9 AuthNextSignInStep nextStep = result.getNextStep();
10 switch (nextStep.getSignInStep()) {
11 case CONFIRM_SIGN_IN_WITH_TOTP_CODE -> {
12 Log.i("AuthQuickstart", "Received next step as confirm sign in with TOTP code");
13 // Prompt the user to enter the TOTP code generated in their authenticator app
14 // Then invoke `confirmSignIn` api with the code
15 break;
16 }
17 case CONTINUE_SIGN_IN_WITH_TOTP_SETUP -> {
18 Log.i("AuthQuickstart", "Received next step as continue sign in by setting up TOTP");
19 Log.i("AuthQuickstart", "Shared secret that will be used to set up TOTP in the authenticator app" + nextStep.getTotpSetupDetails().getSharedSecret());
20 // Prompt the user to enter the TOTP code generated in their authenticator app
21 // Then invoke `confirmSignIn` api with the code
22 break;
23 }
24 case CONTINUE_SIGN_IN_WITH_MFA_SELECTION -> {
25 Log.i("AuthQuickstart", "Received next step as continue sign in by selecting MFA type");
26 Log.i("AuthQuickstart", "Allowed MFA type" + nextStep.getAllowedMFATypes());
27 // Prompt the user to select the MFA type they want to use
28 // Then invoke `confirmSignIn` api with the MFA type
29 break;
30 }
31 case CONFIRM_SIGN_IN_WITH_SMS_MFA_CODE: {
32 Log.i("AuthQuickstart", "SMS code sent to " + nextStep.getCodeDeliveryDetails().getDestination());
33 Log.i("AuthQuickstart", "Additional Info :" + nextStep.getAdditionalInfo());
34 // Prompt the user to enter the SMS MFA code they received
35 // Then invoke `confirmSignIn` api with the code
36 break;
37 }
38 case CONFIRM_SIGN_IN_WITH_CUSTOM_CHALLENGE: {
39 Log.i("AuthQuickstart", "Custom challenge, additional info: " + nextStep.getAdditionalInfo());
40 // Prompt the user to enter custom challenge answer
41 // Then invoke `confirmSignIn` api with the answer
42 break;
43 }
44 case CONFIRM_SIGN_IN_WITH_NEW_PASSWORD: {
45 Log.i("AuthQuickstart", "Sign in with new password, additional info: " + nextStep.getAdditionalInfo());
46 // Prompt the user to enter a new password
47 // Then invoke `confirmSignIn` api with new password
48 break;
49 }
50 case DONE: {
51 Log.i("AuthQuickstart", "SignIn complete");
52 // User has successfully signed in to the app
53 break;
54 }
55 }
56 },
57 error -> {
58 if (error instanceof UserNotConfirmedException) {
59 // User was not confirmed during the signup process.
60 // Invoke `confirmSignUp` api to confirm the user if
61 // they have the confirmation code. If they do not have the
62 // confirmation code, invoke `resendSignUpCode` to send the
63 // code again.
64 // After the user is confirmed, invoke the `signIn` api again.
65 Log.i("AuthQuickstart", "Signup confirmation required" + error);
66 } else if (error instanceof PasswordResetRequiredException) {
67 // User needs to reset their password.
68 // Invoke `resetPassword` api to start the reset password
69 // flow, and once reset password flow completes, invoke
70 // `signIn` api to trigger signIn flow again.
71 Log.i("AuthQuickstart", "Password reset required" + error);
72 } else {
73 Log.e("AuthQuickstart", "SignIn failed: " + error);
74 }
75 }
76
77 );
78} catch (Exception error) {
79 Log.e("AuthQuickstart", "Unexpected error occurred: " + error);
80}
1val options = AWSCognitoAuthSignInOptions.builder().authFlowType(AuthFlowType.USER_SRP_AUTH).build()
2try {
3 Amplify.Auth.signIn(
4 "username",
5 "password",
6 options,
7 { result ->
8 val nextStep = result.nextStep
9 when(nextStep.signInStep){
10 AuthSignInStep.CONFIRM_SIGN_IN_WITH_TOTP_CODE -> {
11 Log.i("AuthQuickstart", "Received next step as confirm sign in with TOTP code")
12 // Prompt the user to enter the TOTP code generated in their authenticator app
13 // Then invoke `confirmSignIn` api with the code
14 }
15 AuthSignInStep.CONTINUE_SIGN_IN_WITH_TOTP_SETUP -> {
16 Log.i("AuthQuickstart", "Received next step as continue sign in by setting up TOTP")
17 Log.i("AuthQuickstart", "Shared secret that will be used to set up TOTP in the authenticator app ${nextStep.totpSetupDetails.sharedSecret}")
18 // Prompt the user to enter the TOTP code generated in their authenticator app
19 // Then invoke `confirmSignIn` api with the code
20 }
21 AuthSignInStep.CONTINUE_SIGN_IN_WITH_MFA_SELECTION -> {
22 Log.i("AuthQuickstart", "Received next step as continue sign in by selecting MFA type")
23 Log.i("AuthQuickstart", "Allowed MFA types ${nextStep.allowedMFATypes}")
24 // Prompt the user to select the MFA type they want to use
25 // Then invoke `confirmSignIn` api with the MFA type
26 }
27 AuthSignInStep.CONFIRM_SIGN_IN_WITH_SMS_MFA_CODE -> {
28 Log.i("AuthQuickstart", "SMS code sent to ${nextStep.codeDeliveryDetails?.destination}")
29 Log.i("AuthQuickstart", "Additional Info ${nextStep.additionalInfo}")
30 // Prompt the user to enter the SMS MFA code they received
31 // Then invoke `confirmSignIn` api with the code
32 }
33 AuthSignInStep.CONFIRM_SIGN_IN_WITH_CUSTOM_CHALLENGE -> {
34 Log.i("AuthQuickstart","Custom challenge, additional info: ${nextStep.additionalInfo}")
35 // Prompt the user to enter custom challenge answer
36 // Then invoke `confirmSignIn` api with the answer
37 }
38 AuthSignInStep.CONFIRM_SIGN_IN_WITH_NEW_PASSWORD -> {
39 Log.i("AuthQuickstart", "Sign in with new password, additional info: ${nextStep.additionalInfo}")
40 // Prompt the user to enter a new password
41 // Then invoke `confirmSignIn` api with new password
42 }
43 AuthSignInStep.DONE -> {
44 Log.i("AuthQuickstart", "SignIn complete")
45 // User has successfully signed in to the app
46 }
47 }
48
49 }
50 ) { error ->
51 if (error is UserNotConfirmedException) {
52 // User was not confirmed during the signup process.
53 // Invoke `confirmSignUp` api to confirm the user if
54 // they have the confirmation code. If they do not have the
55 // confirmation code, invoke `resendSignUpCode` to send the
56 // code again.
57 // After the user is confirmed, invoke the `signIn` api again.
58 Log.i("AuthQuickstart", "Signup confirmation required", error)
59 } else if (error is PasswordResetRequiredException) {
60 // User needs to reset their password.
61 // Invoke `resetPassword` api to start the reset password
62 // flow, and once reset password flow completes, invoke
63 // `signIn` api to trigger signIn flow again.
64 Log.i("AuthQuickstart", "Password reset required", error)
65 } else {
66 Log.e("AuthQuickstart", "Unexpected error occurred: $error")
67 }
68 }
69} catch (error: Exception) {
70 Log.e("AuthQuickstart", "Unexpected error occurred: $error")
71}
1val options =
2 AWSCognitoAuthSignInOptions.builder().authFlowType(AuthFlowType.USER_SRP_AUTH).build()
3try {
4 val result = Amplify.Auth.signIn(
5 "username",
6 "password",
7 options
8 )
9 val nextStep = result.nextStep
10 when (nextStep.signInStep) {
11 AuthSignInStep.CONFIRM_SIGN_IN_WITH_TOTP_CODE -> {
12 Log.i("AuthQuickstart", "Received next step as confirm sign in with TOTP code")
13 // Prompt the user to enter the TOTP code generated in their authenticator app
14 // Then invoke `confirmSignIn` api with the code
15 }
16 AuthSignInStep.CONTINUE_SIGN_IN_WITH_TOTP_SETUP -> {
17 Log.i("AuthQuickstart", "Received next step as continue sign in by setting up TOTP")
18 Log.i("AuthQuickstart", "Shared secret that will be used to set up TOTP in the authenticator app ${nextStep.totpSetupDetails.sharedSecret}")
19 // Prompt the user to enter the TOTP code generated in their authenticator app
20 // Then invoke `confirmSignIn` api with the code
21 }
22 AuthSignInStep.CONTINUE_SIGN_IN_WITH_MFA_SELECTION -> {
23 Log.i("AuthQuickstart", "Received next step as continue sign in by selecting MFA type")
24 Log.i("AuthQuickstart", "Allowed MFA types ${nextStep.allowedMFATypes}")
25 // Prompt the user to select the MFA type they want to use
26 // Then invoke `confirmSignIn` api with the MFA type
27 }
28 AuthSignInStep.CONFIRM_SIGN_IN_WITH_SMS_MFA_CODE -> {
29 Log.i("AuthQuickstart", "SMS code sent to ${nextStep.codeDeliveryDetails?.destination}")
30 Log.i("AuthQuickstart", "Additional Info ${nextStep.additionalInfo}")
31 // Prompt the user to enter the SMS MFA code they received
32 // Then invoke `confirmSignIn` api with the code
33 }
34 AuthSignInStep.CONFIRM_SIGN_IN_WITH_CUSTOM_CHALLENGE -> {
35 Log.i("AuthQuickstart", "Custom challenge, additional info: ${nextStep.additionalInfo}")
36 // Prompt the user to enter custom challenge answer
37 // Then invoke `confirmSignIn` api with the answer
38 }
39 AuthSignInStep.CONFIRM_SIGN_IN_WITH_NEW_PASSWORD -> {
40 Log.i(
41 "AuthQuickstart",
42 "Sign in with new password, additional info: ${nextStep.additionalInfo}"
43 )
44 // Prompt the user to enter a new password
45 // Then invoke `confirmSignIn` api with new password
46 }
47 AuthSignInStep.DONE -> {
48 Log.i("AuthQuickstart", "SignIn complete")
49 // User has successfully signed in to the app
50 }
51 }
52} catch (error: Exception) {
53 if (error is UserNotConfirmedException) {
54 // User was not confirmed during the signup process.
55 // Invoke `confirmSignUp` api to confirm the user if
56 // they have the confirmation code. If they do not have the
57 // confirmation code, invoke `resendSignUpCode` to send the
58 // code again.
59 // After the user is confirmed, invoke the `signIn` api again.
60 Log.i("AuthQuickstart", "Signup confirmation required", error)
61 } else if (error is PasswordResetRequiredException) {
62 // User needs to reset their password.
63 // Invoke `resetPassword` api to start the reset password
64 // flow, and once reset password flow completes, invoke
65 // `signIn` api to trigger signIn flow again.
66 Log.i("AuthQuickstart", "Password reset required", error)
67 } else {
68 Log.e("AuthQuickstart", "Unexpected error occurred: $error")
69 }
70}
1AWSCognitoAuthSignInOptions options = AWSCognitoAuthSignInOptions.builder().authFlowType(AuthFlowType.USER_SRP_AUTH).build();
2RxAmplify.Auth.signIn("username", "password", options).subscribe(
3 result ->
4 {
5 AuthNextSignInStep nextStep = result.getNextStep();
6 switch (nextStep.getSignInStep()) {
7 case CONFIRM_SIGN_IN_WITH_TOTP_CODE -> {
8 Log.i("AuthQuickstart", "Received next step as confirm sign in with TOTP code");
9 // Prompt the user to enter the TOTP code generated in their authenticator app
10 // Then invoke `confirmSignIn` api with the code
11 break;
12 }
13 case CONTINUE_SIGN_IN_WITH_TOTP_SETUP -> {
14 Log.i("AuthQuickstart", "Received next step as continue sign in by setting up TOTP");
15 Log.i("AuthQuickstart", "Shared secret that will be used to set up TOTP in the authenticator app" + nextStep.getTotpSetupDetails().getSharedSecret());
16 // Prompt the user to enter the TOTP code generated in their authenticator app
17 // Then invoke `confirmSignIn` api with the code
18 break;
19 }
20 case CONTINUE_SIGN_IN_WITH_MFA_SELECTION -> {
21 Log.i("AuthQuickstart", "Received next step as continue sign in by selecting MFA type");
22 Log.i("AuthQuickstart", "Allowed MFA type" + nextStep.getAllowedMFATypes());
23 // Prompt the user to select the MFA type they want to use
24 // Then invoke `confirmSignIn` api with the MFA type
25 break;
26 }
27 case CONFIRM_SIGN_IN_WITH_SMS_MFA_CODE: {
28 Log.i("AuthQuickstart", "SMS code sent to " + nextStep.getCodeDeliveryDetails().getDestination());
29 Log.i("AuthQuickstart", "Additional Info :" + nextStep.getAdditionalInfo());
30 // Prompt the user to enter the SMS MFA code they received
31 // Then invoke `confirmSignIn` api with the code
32 break;
33 }
34 case CONFIRM_SIGN_IN_WITH_CUSTOM_CHALLENGE: {
35 Log.i("AuthQuickstart", "Custom challenge, additional info: " + nextStep.getAdditionalInfo());
36 // Prompt the user to enter custom challenge answer
37 // Then invoke `confirmSignIn` api with the answer
38 break;
39 }
40 case CONFIRM_SIGN_IN_WITH_NEW_PASSWORD: {
41 Log.i("AuthQuickstart", "Sign in with new password, additional info: " + nextStep.getAdditionalInfo());
42 // Prompt the user to enter a new password
43 // Then invoke `confirmSignIn` api with new password
44 break;
45 }
46 case DONE: {
47 Log.i("AuthQuickstart", "SignIn complete");
48 // User has successfully signed in to the app
49 break;
50 }
51 }
52 },
53 error -> {
54 if (error instanceof UserNotConfirmedException) {
55 // User was not confirmed during the signup process.
56 // Invoke `confirmSignUp` api to confirm the user if
57 // they have the confirmation code. If they do not have the
58 // confirmation code, invoke `resendSignUpCode` to send the
59 // code again.
60 // After the user is confirmed, invoke the `signIn` api again.
61 Log.i("AuthQuickstart", "Signup confirmation required" + error);
62 } else if (error instanceof PasswordResetRequiredException) {
63 // User needs to reset their password.
64 // Invoke `resetPassword` api to start the reset password
65 // flow, and once reset password flow completes, invoke
66 // `signIn` api to trigger signIn flow again.
67 Log.i("AuthQuickstart", "Password reset required" + error);
68 } else {
69 Log.e("AuthQuickstart", "SignIn failed: " + error);
70 }
71 }
72);

Confirm signin with SMS MFA

If the next step is CONFIRM_SIGN_IN_WITH_SMS_MFA_CODE, Amplify Auth has sent the user a random code over SMS, and is waiting to find out if the user successfully received it. To handle this step, your app's UI must prompt the user to enter the code. After the user enters the code, your implementation must pass the value to Amplify Auth confirmSignIn API.

Note: the signIn result also includes an AuthCodeDeliveryDetails member. It includes additional information about the code delivery such as the partial phone number of the SMS recipient.

1try {
2 Amplify.Auth.confirmSignIn(
3 "confirmation code",
4 result -> {
5 if (result.isSignedIn()) {
6 Log.i("AuthQuickstart", "Confirm signIn succeeded");
7 } else {
8 Log.i("AuthQuickstart", "Confirm sign in not complete. There might be additional steps: " + result.getNextStep());
9 // Switch on the next step to take appropriate actions.
10 // If `signInResult.isSignedIn` is true, the next step
11 // is 'done', and the user is now signed in.
12 }
13 },
14 error -> Log.e("AuthQuickstart", "Confirm sign in failed: " + error)
15 );
16} catch (Exception error) {
17 Log.e("AuthQuickstart", "Unexpected error: " + error);
18}
1try {
2 Amplify.Auth.confirmSignIn(
3 "confirmation code",
4 { result ->
5 if (result.isSignedIn) {
6 Log.i("AuthQuickstart","Confirm signIn succeeded")
7 } else {
8 Log.i("AuthQuickstart", "Confirm sign in not complete. There might be additional steps: ${result.nextStep}")
9 // Switch on the next step to take appropriate actions.
10 // If `signInResult.isSignedIn` is true, the next step
11 // is 'done', and the user is now signed in.
12 }
13 }
14 ) { error -> Log.e("AuthQuickstart", "Confirm sign in failed: $error")}
15} catch (error: Exception) {
16 Log.e("AuthQuickstart", "Unexpected error: $error")
17}
1try {
2 val result = Amplify.Auth.confirmSignIn(
3 "confirmation code"
4 )
5 if (result.isSignedIn) {
6 Log.i("AuthQuickstart", "Confirm signIn succeeded")
7 } else {
8 Log.i("AuthQuickstart", "Confirm sign in not complete. There might be additional steps: ${result.nextStep}"
9 )
10 // Switch on the next step to take appropriate actions.
11 // If `signInResult.isSignedIn` is true, the next step
12 // is 'done', and the user is now signed in.
13 }
14} catch (error: Exception) {
15 Log.e("AuthQuickstart", "Unexpected error: $error")
16}
1RxAmplify.Auth.confirmSignIn(
2 "confirmation code").subscribe(
3 result -> {
4 if (result.isSignedIn()) {
5 Log.i("AuthQuickstart", "Confirm signIn succeeded");
6 } else {
7 Log.i("AuthQuickstart", "Confirm sign in not complete. There might be additional steps: " + result.getNextStep());
8 // Switch on the next step to take appropriate actions.
9 // If `signInResult.isSignedIn` is true, the next step
10 // is 'done', and the user is now signed in.
11 }
12 },
13 error -> Log.e("AuthQuickstart", "Confirm sign in failed: " + error)
14 );

Confirm signin with TOTP MFA

If the next step is confirmSignInWithTOTPCode, you should prompt the user to enter the TOTP code from their associated authenticator app during set up. The code is a six-digit number that changes every 30 seconds. The user must enter the code before the 30-second window expires.

After the user enters the code, your implementation must pass the value to Amplify Auth confirmSignIn API.

Continue signin with MFA Selection

If the next step is continueSignInWithMFASelection, the user must select the MFA method to use. Amplify Auth currently only supports SMS and TOTP as MFA methods. After the user selects an MFA method, your implementation must pass the selected MFA method to Amplify Auth using confirmSignIn API.

Continue signin with TOTP Setup

If the next step is continueSignInWithTOTPSetup, then the user must provide a TOTP code to complete the sign in process. The step returns an associated value of type TOTPSetupDetails which would be used for generating TOTP. TOTPSetupDetails provides a helper method called getSetupURI that can be used to generate a URI, which can be used by native password managers for TOTP association. For example. if the URI is used on Apple platforms, it will trigger the platform's native password manager to associate TOTP with the account. For more advanced use cases, TOTPSetupDetails also contains the sharedSecret that will be used to either generate a QR code or can be manually entered into an authenticator app.

Once the authenticator app is set up, the user can generate a TOTP code and provide it to the library to complete the sign in process.

Confirm signin with custom challenge

If the next step is CONFIRM_SIGN_IN_WITH_CUSTOM_CHALLENGE, Amplify Auth is awaiting completion of a custom authentication challenge. The challenge is based on the Lambda trigger you setup when you configured a custom sign in flow. To complete this step, you should prompt the user for the custom challenge answer, and pass the answer to the confirmSignIn API.

1try {
2 Amplify.Auth.confirmSignIn(
3 "challenge answer",
4 result -> {
5 if (result.isSignedIn()) {
6 Log.i("AuthQuickstart", "Confirm signIn succeeded");
7 } else {
8 Log.i("AuthQuickstart", "Confirm sign in not complete. There might be additional steps: " + result.getNextStep());
9 // Switch on the next step to take appropriate actions.
10 // If `signInResult.isSignedIn` is true, the next step
11 // is 'done', and the user is now signed in.
12 }
13 },
14 error -> Log.e("AuthQuickstart", "Confirm sign in failed: " + error)
15 );
16} catch (Exception error) {
17 Log.e("AuthQuickstart", "Unexpected error: " + error);
18}
1try {
2Amplify.Auth.confirmSignIn(
3 "challenge answer",
4 { result ->
5 if (result.isSignedIn) {
6 Log.i("AuthQuickstart","Confirm signIn succeeded")
7 } else {
8 Log.i("AuthQuickstart", "Confirm sign in not complete. There might be additional steps: ${result.nextStep}")
9 // Switch on the next step to take appropriate actions.
10 // If `signInResult.isSignedIn` is true, the next step
11 // is 'done', and the user is now signed in.
12 }
13 }
14 ) { error ->
15 Log.e("AuthQuickstart", "Confirm sign in failed: $error")
16 }
17} catch (error: Exception) {
18 Log.e("AuthQuickstart", "Unexpected error: $error")
19}
1try {
2 val result = Amplify.Auth.confirmSignIn(
3 "challenge answer"
4 )
5 if (result.isSignedIn) {
6 Log.i("AuthQuickstart", "Confirm signIn succeeded")
7 } else {
8 Log.i("AuthQuickstart", "Confirm sign in not complete. There might be additional steps: ${result.nextStep}")
9 // Switch on the next step to take appropriate actions.
10 // If `signInResult.isSignedIn` is true, the next step
11 // is 'done', and the user is now signed in.
12 }
13} catch (error: Exception) {
14 Log.e("AuthQuickstart", "Unexpected error: $error")
15}
1RxAmplify.Auth.confirmSignIn(
2 "challenge answer").subscribe(
3 result -> {
4 if (result.isSignedIn()) {
5 Log.i("AuthQuickstart", "Confirm signIn succeeded");
6 } else {
7 Log.i("AuthQuickstart", "Confirm sign in not complete. There might be additional steps: " + result.getNextStep());
8 // Switch on the next step to take appropriate actions.
9 // If `signInResult.isSignedIn` is true, the next step
10 // is 'done', and the user is now signed in.
11 }
12 },
13 error -> Log.e("AuthQuickstart", "Confirm sign in failed: " + error)
14 );
Special Handling on ConfirmSignIn

During a confirmSignIn call if failAuthentication=true is returned by the lambda the session of the request gets invalidated by cognito, a NotAuthorizedException is returned and a new signIn call is expected via Amplify.Auth.signIn

1NotAuthorizedException{message=Failed since user is not authorized., cause=NotAuthorizedException(message=Invalid session for the user.), recoverySuggestion=Check whether the given values are correct and the user is authorized to perform the operation.}

Confirm signin with new password

If you receive a UserNotConfirmedException while signing in, Amplify Auth requires a new password for the user before they can proceed. Prompt the user for a new password and pass it to the confirmSignIn API.

1try {
2 Amplify.Auth.confirmSignIn(
3 "confirmation code",
4 result -> {
5 if (result.isSignedIn()) {
6 Log.i("AuthQuickstart", "Confirm signIn succeeded");
7 } else {
8 Log.i("AuthQuickstart", "Confirm sign in not complete. There might be additional steps: " + result.getNextStep());
9 // Switch on the next step to take appropriate actions.
10 // If `signInResult.isSignedIn` is true, the next step
11 // is 'done', and the user is now signed in.
12 }
13 },
14 error -> Log.e("AuthQuickstart", "Confirm sign in failed: " + error)
15 );
16} catch (Exception error) {
17 Log.e("AuthQuickstart", "Unexpected error: " + error);
18}
1try {
2 Amplify.Auth.confirmSignIn(
3 "confirmation code",
4 { result ->
5 if (result.isSignedIn) {
6 Log.i("AuthQuickstart","Confirm signIn succeeded")
7 } else {
8 Log.i("AuthQuickstart", "Confirm sign in not complete. There might be additional steps: ${result.nextStep}")
9 }
10 }
11 ) { error ->
12 Log.e("AuthQuickstart", "Confirm sign in failed: $error")
13 }
14} catch (error: Exception) {
15 Log.e("AuthQuickstart", "Unexpected error: $error")
16}
17}
1try {
2 val result = Amplify.Auth.confirmSignIn(
3 "confirmation code"
4 )
5 if (result.isSignedIn) {
6 Log.i("AuthQuickstart", "Confirm signIn succeeded")
7 } else {
8 Log.i("AuthQuickstart", "Confirm sign in not complete. There might be additional steps: ${result.nextStep}")
9 }
10} catch (error: Exception) {
11 Log.e("AuthQuickstart", "Unexpected error: $error")
12}
1RxAmplify.Auth.confirmSignIn(
2 "confirmation code").subscribe(
3 result -> {
4 if (result.isSignedIn()) {
5 Log.i("AuthQuickstart", "Confirm signIn succeeded");
6 } else {
7 Log.i("AuthQuickstart", "Confirm sign in not complete. There might be additional steps: " + result.getNextStep());
8 }
9 },
10 error -> Log.e("AuthQuickstart", "Confirm sign in failed: " + error)
11 );

Reset password

If you receive PasswordResetRequiredException, authentication flow could not proceed without resetting the password. The next step is to invoke resetPassword api and follow the reset password flow.

1try {
2 Amplify.Auth.resetPassword(
3 "username",
4 result -> Log.i("AuthQuickstart", "Reset password succeeded"),
5 error -> Log.e("AuthQuickstart", "Reset password failed : " + error)
6 );
7} catch (Exception error) {
8 Log.e("AuthQuickstart", "Unexpected error: " + error);
9}
1try {
2 Amplify.Auth.resetPassword(
3 "username",
4 {
5 Log.i("AuthQuickstart", "Reset password succeeded")
6 }
7 ) { error ->
8 Log.e("AuthQuickstart", "Reset password failed : $error")
9 }
10} catch (error: Exception) {
11 Log.e("AuthQuickstart", "Unexpected error: $error")
12}
1try {
2 Amplify.Auth.resetPassword("username")
3 Log.i("AuthQuickstart", "Reset password succeeded")
4} catch (error: Exception) {
5 Log.e("AuthQuickstart", "Unexpected error: $error")
6}
1RxAmplify.Auth.resetPassword(
2 "username").subscribe(
3 result -> Log.i("AuthQuickstart", "Reset password succeeded"),
4 error -> Log.e("AuthQuickstart", "Reset password failed : " + error)
5);

Confirm Signup

If you receive CONFIRM_SIGN_UP as a next step, sign up could not proceed without confirming user information such as email or phone number. The next step is to invoke the confirmSignUp API and follow the confirm signup flow.

1try {
2 Amplify.Auth.confirmSignUp(
3 "username",
4 "confirmation code",
5 result -> Log.i("AuthQuickstart", "Confirm signUp result completed: " + result.isSignUpComplete()),
6 error -> Log.e("AuthQuickstart", "An error occurred while confirming sign up: " + error)
7 );
8} catch (Exception error) {
9 Log.e("AuthQuickstart", "unexpected error: " + error);
10}
1try {
2 Amplify.Auth.confirmSignUp(
3 "username",
4 "confirmation code",
5 { result ->
6 Log.i("AuthQuickstart", "Confirm signUp result completed: ${result.isSignUpComplete}")
7 }
8 ) { error ->
9 Log.e("AuthQuickstart", "An error occurred while confirming sign up: $error")
10 }
11} catch (error: Exception) {
12 Log.e("AuthQuickstart", "unexpected error: $error")
13}
1try {
2 val result = Amplify.Auth.confirmSignUp(
3 "username",
4 "confirmation code"
5 )
6 Log.i("AuthQuickstart", "Confirm signUp result completed: ${result.isSignUpComplete}")
7} catch (error: Exception) {
8 Log.e("AuthQuickstart", "unexpected error: $error")
9}
1RxAmplify.Auth.confirmSignUp(
2 "username",
3 "confirmation code").subscribe(
4 result -> Log.i("AuthQuickstart", "Confirm signUp result completed: " + result.isSignUpComplete()),
5 error -> Log.e("AuthQuickstart", "An error occurred while confirming sign up: " + error)
6);

Get Current User

This call fetches the current logged in user and should be used after a user has been successfully signed in. If the user is signed in, it will return the current userId and username. Note: An empty string will be assigned to userId and/or username, if the values are not present in the accessToken.

1try {
2 Amplify.Auth.getCurrentUser(
3 result -> Log.i("AuthQuickstart", "Current user details are:" + result.toString(),
4 error -> Log.e("AuthQuickstart", "getCurrentUser failed with an exception: " + error)
5 );
6 } catch (Exception error) {
7 Log.e("AuthQuickstart", "unexpected error: " + error);
8 }
1Amplify.Auth.getCurrentUser({
2 Log.i("AuthQuickStart", "Current user details are: $it")},{
3 Log.e("AuthQuickStart", "getCurrentUser failed with an exception: $it")
4})
1try {
2 val result = Amplify.Auth.getCurrentUser()
3 Log.i("AuthQuickstart", "Current user details are: $result")
4} catch (error: Exception) {
5 Log.e("AuthQuickstart", "getCurrentUser failed with an exception: $error")
6}
1RxAmplify.Auth.getCurrentUser().subscribe(
2 result -> Log.i("AuthQuickStart getCurrentUser: " + result.toString()),
3 error -> Log.e("AuthQuickStart", error.toString())
4 );

Done

Sign In flow is complete when you get done. This means the user is successfully authenticated. As a convenience, the SignInResult also provides the isSignedIn property, which will be true if the next step is done.