aws-amplify / amplify-android

The fastest and easiest way to use AWS from your Android app.
https://docs.amplify.aws/lib/q/platform/android/
Apache License 2.0
249 stars 117 forks source link

Unable to switch to sign up flow while in sign in flow #2942

Open sailquilt opened 2 weeks ago

sailquilt commented 2 weeks ago

Before opening, please confirm:

Language and Async Model

Kotlin - Coroutines

Amplify Categories

Authentication

Gradle script dependencies

```groovy // Put output below this line awsAuthCognito = "2.24.0" aws-auth-cognito = { group = "com.amplifyframework", name = "aws-auth-cognito", version.ref = "awsAuthCognito" } aws-core-kotlin = { group = "com.amplifyframework", name = "core-kotlin", version.ref = "awsAuthCognito" } implementation(libs.aws.auth.cognito) implementation(libs.aws.core.kotlin) ```

Environment information

``` # Put output below this line ------------------------------------------------------------ Gradle 8.7 ------------------------------------------------------------ Build time: 2024-03-22 15:52:46 UTC Revision: 650af14d7653aa949fce5e886e685efc9cf97c10 Kotlin: 1.9.22 Groovy: 3.0.17 Ant: Apache Ant(TM) version 1.10.13 compiled on January 4 2023 JVM: 22.0.2 (Homebrew 22.0.2) OS: Mac OS X 14.6.1 aarch64 ```

Please include any relevant guides or documentation you're referencing

No response

Describe the bug

When switching from the sign in flow to sign up flow, we get the following error:

Auth state is an invalid state, cannot process the request.

Reproduction steps (if applicable)

No response

Code Snippet

// Put your code below this line.
            val authResult = Amplify.Auth.signIn(
                username = email,
                password = "",
            )

// The above returns CONFIRM_SIGN_IN_WITH_CUSTOM_CHALLENGE

          val authResult = Amplify.Auth.signUp(
                username = email,
                password = generateUUID()
            )

// This throws InvalidStateException

Log output

``` // Put your logs below this line 11-04 12:46:22.626 D/ConnectivityManager( 9271): StackLog: [android.net.ConnectivityManager.sendRequestForNetwork(ConnectivityManager.java:4692)] [android.net.ConnectivityManager.registerDefaultNetworkCallbackForUid(ConnectivityManager.java:5381)] [android.net.ConnectivityManager.registerDefaultNetworkCallback(ConnectivityManager.java:5348)] [android.net.ConnectivityManager.registerDefaultNetworkCallback(ConnectivityManager.java:5322)] [io.sentry.android.core.internal.util.AndroidConnectionStatusProvider.registerNetworkCallback(AndroidConnectionStatusProvider.java:307)] [io.sentry.android.core.NetworkBreadcrumbsIntegration.register(NetworkBreadcrumbsIntegration.java:77)] [io.sentry.Sentry.init(Sentry.java:255)] [io.sentry.Sentry.init(Sentry.java:167)] [io.sentry.android.core.SentryAndroid.init(SentryAndroid.java:94)] [io.sentry.android.core.SentryAndroid.init(SentryAndroid.java:77)] [com.quilt.android.clientservices.SentryService.configureSentry(SentryService.kt:19)] [com.quilt.android.QuiltApplication.onCreate(QuiltApplication.kt:29)] [android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1316)] [android.app.ActivityThread.handleBindApplication(ActivityThread.java:7848)] [android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)] [android.app.ActivityThread$H.handleMessage(ActivityThread.java:2486)] 11-04 12:46:22.710 I/Quilt ( 9271): 🟢 [KMP:NetworkController] - Using development network configuration 11-04 12:46:22.806 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): Auth State Change: NotConfigured(id=) 11-04 12:46:22.807 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): Auth State Change: ConfiguringAuth(id=) 11-04 12:46:22.807 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): InitAuthConfig Starting execution 11-04 12:46:22.808 I/Quilt ( 9271): 🟢 [KMP:AuthenticationController] - restorePreviousSignIn 11-04 12:46:22.809 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): Credential Store State Change: NotConfigured(id=) 11-04 12:46:22.809 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): Credential Store State Change: MigratingLegacyStore(id=) 11-04 12:46:22.809 I/Quilt ( 9271): 🟢 [KMP:ActiveUserController] - onRestorePreviousSignIn, user is not signed in 11-04 12:46:22.810 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): MigrateLegacyCredentials Starting execution 11-04 12:46:22.810 I/Quilt ( 9271): 🟢 [KMP:ActiveUserController] - updateUserState, Uninitialized -> SignedOut(isViewLoaded=false, isSessionExpired=false) 11-04 12:46:22.826 I/Quilt ( 9271): 🟢 [Android:AppLifecycleObserver] - onStart, ignoring first onStart after app launch 11-04 12:46:22.831 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): MigrateLegacyCredentials Sending event LoadCredentialStore 11-04 12:46:22.832 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): Credential Store State Change: LoadingStoredCredentials(id=) 11-04 12:46:22.832 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): LoadCredentialStore Starting execution 11-04 12:46:22.838 I/IDS_TAG ( 9271): Getting Shared Preference for com.quilt.android.QuiltApplication@d99fa7d uid = 10568 11-04 12:46:22.840 I/IDS_TAG ( 9271): App com.quilt.android.QuiltApplication@d99fa7d has not finished training 11-04 12:46:22.841 I/IDS_TAG ( 9271): Getting Shared Preference for com.quilt.android.QuiltApplication@d99fa7d uid = 10568 11-04 12:46:22.841 I/IDS_TAG ( 9271): IDS count updated to 2 for com.quilt.android.QuiltApplication@d99fa7d 11-04 12:46:22.929 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): LoadCredentialStore Sending event CompletedOperation 11-04 12:46:22.929 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): Credential Store State Change: Success(storedCredentials=com.amplifyframework.statemachine.codegen.data.AmplifyCredential$Empty@100d533) 11-04 12:46:22.929 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): MoveToIdleState Starting execution 11-04 12:46:22.929 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): MoveToIdleState Sending event MoveToIdleState 11-04 12:46:22.930 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): Credential Store State Change: Idle(id=) 11-04 12:46:22.930 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): InitAuthConfig Sending event ConfigureAuthentication 11-04 12:46:22.930 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): Auth State Change: ConfiguringAuthentication(authNState=NotConfigured(id=)) 11-04 12:46:22.931 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): InitAuthNConfig Starting execution 11-04 12:46:22.931 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): InitAuthNConfig Sending event Configure 11-04 12:46:22.931 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): Auth State Change: ConfiguringAuthentication(authNState=Configured(id=)) 11-04 12:46:22.931 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): ConfigureAuthN Starting execution 11-04 12:46:22.932 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): ConfigureAuthN Sending event InitializedSignedOut 11-04 12:46:22.932 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): ConfigureAuthN Sending event ConfiguredAuthentication 11-04 12:46:22.932 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): Auth State Change: ConfiguringAuthentication(authNState=SignedOut(signedOutData=SignedOutData(lastKnownUsername=null, hostedUIErrorData=null, globalSignOutErrorData=null, revokeTokenErrorData=null))) 11-04 12:46:22.932 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): Auth State Change: ConfiguringAuthorization(authNState=SignedOut(signedOutData=SignedOutData(lastKnownUsername=null, hostedUIErrorData=null, globalSignOutErrorData=null, revokeTokenErrorData=null)), authZState=NotConfigured(id=)) 11-04 12:46:22.933 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): InitAuthZConfig Starting execution 11-04 12:46:22.933 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): InitAuthZConfig Sending event Configure 11-04 12:46:22.933 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): Auth State Change: ConfiguringAuthorization(authNState=SignedOut(signedOutData=SignedOutData(lastKnownUsername=null, hostedUIErrorData=null, globalSignOutErrorData=null, revokeTokenErrorData=null)), authZState=Configured(id=)) 11-04 12:46:22.933 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): ConfigureAuthZ Starting execution 11-04 12:46:22.933 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): ConfigureAuthZ Sending event ConfiguredAuthorization 11-04 12:46:22.934 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): Auth State Change: Configured(authNState=SignedOut(signedOutData=SignedOutData(lastKnownUsername=null, hostedUIErrorData=null, globalSignOutErrorData=null, revokeTokenErrorData=null)), authZState=Configured(id=)) 11-04 12:46:23.236 I/Quilt ( 9271): 🟢 [Android:SplashScreenPreDrawListener] - isAppReady, userState: null -> SignedOut(isViewLoaded=false, isSessionExpired=false), isAppReady: false 11-04 12:46:23.258 I/Quilt ( 9271): 🟢 [KMP:HandledExceptions] - Breadcrumb: sign_in, navigation 11-04 12:46:23.273 I/Quilt ( 9271): 🟢 [KMP:HandledExceptions] - Breadcrumb: sign_in, navigation 11-04 12:46:23.443 I/Quilt ( 9271): 🟢 [KMP:ActiveUserController] - onViewLoaded 11-04 12:46:23.443 I/Quilt ( 9271): 🟢 [KMP:ActiveUserController] - updateUserState, SignedOut(isViewLoaded=false, isSessionExpired=false) -> SignedOut(isViewLoaded=true, isSessionExpired=false) 11-04 12:46:23.466 I/Quilt ( 9271): 🟢 [Android:SplashScreenPreDrawListener] - isAppReady, userState: SignedOut(isViewLoaded=false, isSessionExpired=false) -> SignedOut(isViewLoaded=true, isSessionExpired=false), isAppReady: true 11-04 12:46:23.466 I/Quilt ( 9271): 🟢 [Android:SplashScreenPreDrawListener] - onAppReady 11-04 12:46:25.369 I/Quilt ( 9271): 🟢 [KMP:HandledExceptions] - Breadcrumb: sign_in_with_email, navigation 11-04 12:46:33.461 I/Quilt ( 9271): 🟢 [KMP:AuthenticationController] - signInWithEmail 11-04 12:46:33.461 I/Quilt ( 9271): 🟢 [Android:CognitoService] - signInWithEmail, calling signIn 11-04 12:46:33.469 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): Auth State Change: Configured(authNState=SigningIn(signInState=NotStarted(id=)), authZState=SigningIn(id=)) 11-04 12:46:33.469 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): InitiateSignInAction Starting execution 11-04 12:46:33.469 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): InitiateSignInAction Sending event InitiateSignInWithCustom 11-04 12:46:33.470 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): Auth State Change: Configured(authNState=SigningIn(signInState=SigningInWithCustom(customSignInState=NotStarted(id=))), authZState=SigningIn(id=)) 11-04 12:46:33.470 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): StartCustomAuth Starting execution 11-04 12:46:33.471 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): StartCustomAuth Sending event InitiateCustomSignIn 11-04 12:46:33.472 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): Auth State Change: Configured(authNState=SigningIn(signInState=SigningInWithCustom(customSignInState=Initiating(id=))), authZState=SigningIn(id=)) 11-04 12:46:33.472 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): InitCustomAuth Starting execution 11-04 12:46:33.473 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): Credential Store State Change: LoadingStoredCredentials(id=) 11-04 12:46:33.473 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): Credential Store State Change: Idle(id=) 11-04 12:46:33.473 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): LoadCredentialStore Starting execution 11-04 12:46:33.475 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): LoadCredentialStore Sending event CompletedOperation 11-04 12:46:33.475 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): Credential Store State Change: Success(storedCredentials=ASFDevice(id=849b4a7c-39c9-4b9a-b0e0-3896a3a7ed10:1730144962298)) 11-04 12:46:33.475 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): MoveToIdleState Starting execution 11-04 12:46:33.475 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): MoveToIdleState Sending event MoveToIdleState 11-04 12:46:33.475 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): Credential Store State Change: Idle(id=) 11-04 12:46:33.480 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): Credential Store State Change: Idle(id=) 11-04 12:46:33.480 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): Credential Store State Change: LoadingStoredCredentials(id=) 11-04 12:46:33.481 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): LoadCredentialStore Starting execution 11-04 12:46:33.483 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): LoadCredentialStore Sending event CompletedOperation 11-04 12:46:33.483 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): Credential Store State Change: Success(storedCredentials=DeviceData(deviceMetadata=com.amplifyframework.statemachine.codegen.data.DeviceMetadata$Empty@826c739)) 11-04 12:46:33.483 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): MoveToIdleState Starting execution 11-04 12:46:33.483 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): MoveToIdleState Sending event MoveToIdleState 11-04 12:46:33.483 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): Credential Store State Change: Idle(id=) 11-04 12:46:34.243 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): InitCustomAuth Sending event ReceivedChallenge 11-04 12:46:34.243 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): Auth State Change: Configured(authNState=SigningIn(signInState=ResolvingChallenge(challengeState=NotStarted(id=))), authZState=SigningIn(id=)) 11-04 12:46:34.244 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): InitResolveChallenge Starting execution 11-04 12:46:34.244 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): InitResolveChallenge Sending event WaitForAnswer 11-04 12:46:34.245 V/amplify:aws-cognito-auth:AWSCognitoAuthPlugin( 9271): Auth State Change: Configured(authNState=SigningIn(signInState=ResolvingChallenge(challengeState=WaitingForAnswer(challenge=AuthChallenge(challengeName=CUSTOM_CHALLENGE, username=..., session=..-..-.., parameters={USERNAME=..., email=sail@quilt.com}), hasNewResponse=false))), authZState=SigningIn(id=)) 11-04 12:46:34.247 I/Quilt ( 9271): 🟢 [Android:CognitoService] - signInWithEmail, authResult: AuthSignInResult{isSignedIn=false, nextStep=AuthNextSignInStep{signInStep=CONFIRM_SIGN_IN_WITH_CUSTOM_CHALLENGE, additionalInfo={USERNAME=..., email=sail@quilt.com}, codeDeliveryDetails=null, totpSetupDetails=null, allowedMFATypes=null}} 11-04 12:46:34.247 I/Quilt ( 9271): 🟢 [KMP:ActiveUserController] - onSignIn, user is not signed in 11-04 12:46:34.248 I/Quilt ( 9271): 🟢 [KMP:ActiveUserController] - updateUserState, SignedOut(isViewLoaded=true, isSessionExpired=false) -> SignedOut(isViewLoaded=true, isSessionExpired=false) 11-04 12:46:34.272 I/Quilt ( 9271): 🟢 [KMP:HandledExceptions] - Breadcrumb: email_signin_code_entry/{email}, navigation 11-04 12:46:35.809 I/Quilt ( 9271): 🟢 [KMP:HandledExceptions] - Breadcrumb: sign_in_with_email, navigation 11-04 12:46:46.155 I/Quilt ( 9271): 🟢 [KMP:AuthenticationController] - signInWithEmail 11-04 12:46:46.155 I/Quilt ( 9271): 🟢 [Android:CognitoService] - signUpOrSignInWithEmail, first trying sign up 11-04 12:46:46.159 E/Quilt ( 9271): 🔴 [KMP:HandledExceptions] - Handled exception InvalidStateException{message=Auth state is an invalid state, cannot process the request., cause=null, recoverySuggestion=Operation performed is not a valid operation for the current auth state.} 11-04 12:46:46.312 I/Quilt ( 9271): 🟢 [KMP:ActiveUserController] - onSignIn, user is not signed in 11-04 12:46:46.313 I/Quilt ( 9271): 🟢 [KMP:ActiveUserController] - updateUserState, SignedOut(isViewLoaded=true, isSessionExpired=false) -> SignedOut(isViewLoaded=true, isSessionExpired=false) ```

amplifyconfiguration.json

No response

GraphQL Schema

```graphql // Put your schema below this line ```

Additional information and screenshots

No response

sailquilt commented 2 weeks ago

I wonder if having an explicit API to cancel the sign in flow would help? Similar to the request here: https://github.com/aws-amplify/amplify-android/issues/2604

edisooon commented 2 weeks ago

Hi @sailquilt, thank you for submitting the issue. One of our team members will do some investigation on this as soon as possible.