aws-amplify / aws-amplify/amplify-android

Version 2.30.4 Amplify.Auth.getCurrentUser issue

Open
#3,166 12 comments 0 reactions 0 assignees View on GitHub
auth pending-community-response question
Dominant language
Java
Stars
287
Forks
132
Avg merge
2d 2h
Merged PRs (30d)
45

Description

### Before opening, please confirm:

- [x] I have [searched for duplicate or closed issues](https://github.com/aws-amplify/amplify-android/issues?q=is%3Aissue+) and [discussions](https://github.com/aws-amplify/amplify-android/discussions).

### Language and Async Model

RxJava

### Amplify Categories

Authentication

### Gradle script dependencies

dependencies.add("implementation", libs.amplify.api)
dependencies.add("implementation", libs.amplify.auth)
dependencies.add("implementation", libs.amplify.core)
dependencies.add("implementation", libs.amplify.pinpoint)
dependencies.add("implementation", libs.amplify.rxbindings)
dependencies.add("implementation", libs.amplify.storage)

### Environment information

```
------------------------------------------------------------
Gradle 8.13
------------------------------------------------------------

Build time: 2025-02-25 09:22:14 UTC
Revision: 073314332697ba45c16c0a0ce1891fa6794179ff

Kotlin: 2.0.21
Groovy: 3.0.22
Ant: Apache Ant(TM) version 1.10.15 compiled on August 25 2024
Launcher JVM: 21.0.8 (JetBrains s.r.o. 21.0.8+-14196175-b1038.72)
Daemon JVM: D:\Programs\Studio\jbr (no JDK specified, using current Java home)
OS: Windows 11 10.0 amd64

```

### Please include any relevant guides or documentation you're referencing

_No response_

### Describe the bug

Because of that huge issue with 2.30.2, 2.30.3, when I update to 2.30.4 I did a workaround to sign out the users with a bad state:
- when the user will arrive in the Mainscreen of app I am doing a check comparing the local user with Amplify.Auth.getCurrentUser and I check auth?.userId.

App Flow:
1. In Application I initialize the Amplify SDK using **RxAmplify**. (remember this is important), if something appear a error in Splashscreen I show it, so the user will not open the Mainscreen of the app.
2. If init was fine, appear Splashscreen, then Mainscreen where I am doing that addional check.
3. On this addional check instead to use **RxAmplify.Auth.currentUser**, I am using **Amplify.Auth.getCurrentUser**.

And on step 3 I get this error, but not all the time:
Fatal Exception: java.lang.IllegalStateException: Tried to get a plugin but that plugin was not present. Check if the plugin was added originally or perhaps was already removed.
at com.amplifyframework.core.category.Category.getPluginIfConfiguredOrThrow(Category.java:257)
at com.amplifyframework.core.category.Category.getSelectedPlugin(Category.java:252)
at com.amplifyframework.auth.AuthCategory.getCurrentUser(AuthCategory.java:381)
at com.bfan.sso.logic.services.amplify.state.AmplifyState$register$1.invokeSuspend(AmplifyState.kt:35)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:34)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:100)
at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:124)
at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:89)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:586)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:820)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:717)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:704)

This is my class where I am doing that check: at com.bfan.sso.logic.services.amplify.state.AmplifyState.

Base on your documentation there should not be a problem if I am using **RxAmplify** and **Amplify**, but I remember in the past I created a similar issue with **RxAmplify.Analytics** vs **Amplify.Analytics** and there was a real issue, you can search in history.
https://github.com/aws-amplify/amplify-android/issues/2943

Please help me with this issue, the app is live in store and I have no idea what is wrong.

### Reproduction steps (if applicable)

_No response_

### Code Snippet

```kotlin
// Put your code below this line.

Amplify init:

private Completable initAmplify() {
return Completable.fromAction(() -> {
if (amplifyConfigured.get()) return;
synchronized (amplifyConfigured) {
if (amplifyConfigured.get()) return;
AWSApiPlugin apiPlugin = AWSApiPlugin.builder()
.configureClient("-----", okHttpBuilder -> okHttpBuilder.addInterceptor(chain -> {
Request originalRequest = chain.request();
String modifiedUrl = originalRequest.url().toString()
.replace("+", "%2B")
.replace(";", "%3B")
.replace("#", "%23");

Request modifiedRequest = originalRequest.newBuilder()
.url(modifiedUrl)
.build();

LogUtils.i("RxAmplify URL: " + modifiedRequest.url().url());
return chain.proceed(modifiedRequest);

})).configureClient("-----", okHttpBuilder -> okHttpBuilder.addInterceptor(chain -> {
Request originalRequest = chain.request();
String modifiedUrl = originalRequest.url().toString()
.replace("+", "%2B")
.replace(";", "%3B")
.replace("#", "%23");

Request modifiedRequest = originalRequest.newBuilder()
.url(modifiedUrl)
.build();

LogUtils.i("RxAmplify URL: " + modifiedRequest.url().url());
return chain.proceed(modifiedRequest);

})).configureClient("-----", okHttpBuilder -> okHttpBuilder.addInterceptor(chain -> {
Request originalRequest = chain.request();
String modifiedUrl = originalRequest.url().toString()
.replace("+", "%2B")
.replace(";", "%3B")
.replace("#", "%23");

Request modifiedRequest = originalRequest.newBuilder()
.url(modifiedUrl)
.build();

LogUtils.i("RxAmplify URL: " + modifiedRequest.url().url());
return chain.proceed(modifiedRequest);

})).build();
apiPlugin.configure(AmplifyConfig.Companion.getInstance().getApiConfiguration(), AppApplication.Companion.getInstance());

RxAmplify.addPlugin(apiPlugin);
RxAmplify.addPlugin(new AWSCognitoAuthPlugin());
RxAmplify.addPlugin(new AWSS3StoragePlugin());
RxAmplify.addPlugin(new AWSPinpointAnalyticsPlugin());

AmplifyConfiguration configuration = AmplifyConfiguration.builder(AmplifyConfig.Companion.getInstance().getAWSConfiguration())
.devMenuEnabled(BuildConfig.DEBUG)
.build();
RxAmplify.configure(configuration, AppApplication.Companion.getInstance());
amplifyConfigured.set(true);
}
});
}

State check:

private val checkTyp = CheckType.USER

fun register(currentUser: User?, callback: UiCallback) {
owner.lifecycleScope.launch(Dispatchers.IO) {
if (checkTyp == CheckType.USER_ATTRIBUTES) {
Amplify.Auth.fetchUserAttributes({ attrs ->
owner.lifecycleScope.launch(Dispatchers.Main) {
handlerSuccess(currentUser, attrs, callback)
}

}, { _ ->
owner.lifecycleScope.launch(Dispatchers.Main) {
handlerError(currentUser, callback)
}
})
} else {
Amplify.Auth.getCurrentUser({ value ->
owner.lifecycleScope.launch(Dispatchers.Main) {
handlerSuccess(currentUser, value, callback)
}
}) {
owner.lifecycleScope.launch(Dispatchers.Main) {
handlerError(currentUser, callback)
}
}
}
}
}
```

### Log output

```
// Put your logs below this line

```

### Configuration File

_No response_

### GraphQL Schema

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

```

### Additional information and screenshots

_No response_

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the RxAmplify initialization code and the AmplifyState.kt check that calls Amplify.Auth.getCurrentUser. Trace the reported stack through Category.java and AuthCategory.java, and compare it with the referenced issue #2943. Done means establishing a reproducible cause for the missing plugin error and documenting or validating the corresponding resolution.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java, kotlin
Domain
authentication, mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.