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

Fatal Exception: com.amplifyframework.auth.exceptions.InvalidStateException #2641

Closed sanjeet-nosh closed 10 months ago

sanjeet-nosh commented 1 year ago

Before opening, please confirm:

Language and Async Model

Kotlin - Coroutines

Amplify Categories

Authentication

Gradle script dependencies

```groovy // Put output below this line plugins { id 'com.android.application' id 'kotlin-android' id 'com.google.gms.google-services' id 'com.google.firebase.crashlytics' id 'com.google.devtools.ksp' id 'kotlin-parcelize' } android { compileSdkVersion 33 //it was 30 previously buildToolsVersion "30.0.3" defaultConfig { applicationId "com.euphotic.sbcApp" minSdkVersion 28 targetSdkVersion 33 //it was 30 previously versionCode 35 versionName "3.8.4" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true // externalNativeBuild { // cmake { // cppFlags "-std=c++17" // } // } // ndkVersion = "21.1.6352462" } sourceSets { main { // assets.srcDirs = ['models'] } } aaptOptions { noCompress "tflite" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } compileOptions { coreLibraryDesugaringEnabled true sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } kotlinOptions { jvmTarget = '1.8' } buildFeatures { viewBinding = true } externalNativeBuild { cmake { path file('src/main/cpp/CMakeLists.txt') version '3.22.1' } ndkVersion '25.1.8937393' androidResources { noCompress 'tflite' } namespace 'com.euphotic.sbcApp' } // cmake { // path file('src/main/cpp/CMakeLists.txt') // version '3.22.1' // } } dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib:1.6.20" //it was 1.5.31 previously implementation 'androidx.core:core-ktx:1.7.0' implementation 'androidx.appcompat:appcompat:1.4.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.2' implementation 'androidx.compose.ui:ui-graphics:1.0.0-rc01' implementation 'androidx.databinding:baseLibrary:3.2.0-alpha11' implementation 'androidx.lifecycle:lifecycle-service:2.5.1' implementation 'androidx.navigation:navigation-fragment-ktx:2.5.3' implementation 'androidx.navigation:navigation-ui-ktx:2.5.3' implementation 'androidx.work:work-runtime-ktx:2.7.1' implementation 'com.airbnb.android:lottie:3.7.0' implementation 'androidx.annotation:annotation:1.3.0' implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.5.1' implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1' implementation 'androidx.legacy:legacy-support-v4:1.0.0' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' implementation "androidx.camera:camera-camera2:1.0.2" implementation "androidx.camera:camera-lifecycle:1.0.2" implementation "androidx.camera:camera-view:1.0.0-alpha32" implementation 'org.dizitart:nitrite:3.4.4' implementation 'com.squareup.picasso:picasso:2.71828' implementation 'com.github.Trendyol:BubbleScrollBar:0.1' implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0" implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.4.0" implementation "com.koushikdutta.ion:ion:3.1.0" // Amplify core dependency // implementation 'com.amplifyframework:core:2.2.2' // Support for Java 8 features coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5' // AWS IoT implementation 'com.amazonaws:aws-android-sdk-iot:2.71.0' implementation 'com.amplifyframework:core-kotlin:2.14.2' implementation 'com.amplifyframework:aws-api:2.14.2' implementation 'com.amplifyframework:core:2.14.2' implementation 'com.amplifyframework:aws-auth-cognito:2.14.2' implementation 'org.dizitart:nitrite:3.4.4' //GSON implementation 'com.google.code.gson:gson:2.8.6' implementation 'org.dizitart:potassium-nitrite:3.4.2' implementation 'com.squareup.retrofit2:retrofit:2.9.0' implementation 'com.squareup.retrofit2:converter-gson:2.9.0' implementation "com.squareup.okhttp3:logging-interceptor:4.10.0" implementation "org.slf4j:slf4j-simple:1.6.1" //USB Serial library implementation 'com.github.mik3y:usb-serial-for-android:v3.4.4' implementation 'com.amazonaws:aws-android-sdk-cloudwatch:2.41.1' //QR generator implementation 'androidmads.library.qrgenearator:QRGenearator:1.0.4' implementation 'com.google.zxing:core:3.3.2' //cloudwatch logs sdk implementation 'com.amazonaws:aws-android-sdk-cloudwatch:2.41.1' implementation 'com.amazonaws:aws-android-sdk-logs:2.42.0' implementation platform('com.google.firebase:firebase-bom:30.2.0') implementation 'com.google.firebase:firebase-analytics' implementation 'com.google.firebase:firebase-crashlytics:17.4.1' implementation 'com.google.firebase:firebase-crashlytics-ktx:18.3.7' implementation 'com.google.firebase:firebase-analytics-ktx' //gif implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.17' //seekbar implementation 'com.github.Yokeshthebouncer:IndicatorSeekBarWithHint:1.1.1' // Aws SDK implementation 'com.amazonaws:aws-android-sdk-core:2.6.+' implementation 'com.amazonaws:aws-android-sdk-cognito:2.2.+' // implementation 'com.amazonaws:aws-android-sdk-s3:2.6.+' implementation("com.amazonaws:aws-android-sdk-s3:2.67.0") implementation 'com.amazonaws:aws-android-sdk-ddb:2.2.+' implementation "io.reactivex.rxjava3:rxjava:3.0.4" implementation 'io.reactivex.rxjava3:rxandroid:3.0.0' //qr-code implementation 'com.github.yuriy-budiyev:code-scanner:2.1.0' // custom crash activity //implementation 'cat.ereza:customactivityoncrash:2.4.0' //debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.9.1' //releaseImplementation 'com.squareup.leakcanary:leakcanary-android:2.9.1' //material library implementation 'com.google.android.material:material:1.9.0' // Slider Button implementation 'com.github.MAXDeliveryNG:slideview:1.1.0' //vertical Progress bar implementation "com.github.skydoves:progressview:1.1.3" //lottie files implementation "com.airbnb.android:lottie:3.7.0" // Glide : for faster image loading implementation 'com.github.bumptech.glide:glide:4.14.2' annotationProcessor 'com.github.bumptech.glide:compiler:4.14.2' implementation 'io.github.ShawnLin013:number-picker:2.4.13' def room_version = "2.5.2" implementation "androidx.room:room-runtime:$room_version" annotationProcessor "androidx.room:room-compiler:$room_version" ksp "androidx.room:room-compiler:$room_version" //koin for di def koin_version = "3.4.3" implementation "io.insert-koin:koin-android:$koin_version" } ```

Environment information

``` # Put output below this line env: sh\r: No such file or directory ```

Please include any relevant guides or documentation you're referencing

https://docs.amplify.aws/android/build-a-backend/auth/set-up-auth/

Describe the bug

After logging out from one user, when try to login again with new user it is throwing :

Fatal Exception: com.amplifyframework.auth.exceptions.InvalidStateException Auth state is an invalid state, cannot process the request. com.amplifyframework.auth.cognito.RealAWSCognitoAuthPlugin$fetchAuthSession$1.invoke (RealAWSCognitoAuthPlugin.kt:1163) com.amplifyframework.auth.cognito.RealAWSCognitoAuthPlugin$fetchAuthSession$1.invoke (RealAWSCognitoAuthPlugin.kt:1110) com.amplifyframework.statemachine.StateMachine$getCurrentState$1.invokeSuspend (StateMachine.kt:121)

Reproduction steps (if applicable)

No response

Code Snippet

// Put your code below this line.

Log output

``` // Put your logs below this line ```

amplifyconfiguration.json

{ "UserAgent": "aws-amplify-cli/2.0", "Version": "1.0", "api": { xxxx } }, "auth": { "plugins": { "awsCognitoAuthPlugin": { "UserAgent": "aws-amplify-cli/0.1.0", "Version": "0.1.0", "IdentityManager": { "Default": {} }, "CredentialsProvider": { "CognitoIdentity": { "Default": { "PoolId":xx, "Region": "ap-south-1" } } }, "CognitoUserPool": { "Default": { "PoolId": "ap-south-1_jvyEjtkKf", "AppClientId": xx, "Region": "ap-south-1" } }, "Auth": { "Default": { "authenticationFlowType": "CUSTOM_AUTH" } } } } } }

GraphQL Schema

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

Additional information and screenshots

No response

tjleing commented 1 year ago

Hello @sanjeet-nosh, thanks for reaching out. A couple of quick questions -- how are you calling sign in and sign out? If you're using Amplify.signOut() etc., handling the signOutResult returned should tell you what error is occurring that prevents signing in afterwards (docs).

Also, I also see dependencies on Amplify as well as the AWS Android SDK, which are incompatible if for example you're trying to sign in using Amplify.signIn() and then use the AWS SDK IoT with those credentials.

tylerjroach commented 1 year ago

@sanjeet-nosh It is possible to use IoT with Amplify v2 by using a custom credentials provider to pass Amplify v2 credentials into IoT. However, you cannot mix other AWS Android SDK packages with Amplify v2, especially com.amazonaws:aws-android-sdk-cognito. The SDK Cognito library and Amplify v2 Cognito library are incompatible in the same project.

mattcreaser commented 10 months ago

Closing this issue due to inactivity. Please feel free to open a new issue if required, thanks!

github-actions[bot] commented 10 months ago

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.