aws-amplify / aws-amplify/amplify-android

Auth.getCurrentUser returns user sub even if user logged in with email

Open
#3,133 4 comments 0 reactions 0 assignees View on GitHub
auth feature-request
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

Java

### Amplify Categories

Authentication

### Gradle script dependencies

```
def aws_amplify_version = '2.30.1'
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.5")
implementation "com.amplifyframework:aws-api:$aws_amplify_version"
implementation "com.amplifyframework:aws-auth-cognito:$aws_amplify_version"
implementation "com.amplifyframework:core:$aws_amplify_version"
```

### Environment information

```
------------------------------------------------------------
Gradle 8.14.2
------------------------------------------------------------

Build time: 2025-06-05 13:32:01 UTC
Revision: 30db2a3bdfffa9f8b40e798095675f9dab990a9a

Kotlin: 2.0.21
Groovy: 3.0.24
Ant: Apache Ant(TM) version 1.10.15 compiled on August 25 2024
Launcher JVM: 17.0.12 (Oracle Corporation 17.0.12+8-LTS-286)
Daemon JVM: E:\Programare\jdk-17.0.12 (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

Auth.getCurrentUser returns user sub even if user logged in with email.

The AWS Mobile Client was returning the email in such cases. The javadoc said:

```
/**
* Returns the username attribute of the current access token. Note that the value stored in the username
* attribute of the access token may vary depending on how sign-in was performed. For example, if the user signed in
* with email, the username attribute will have the email address.
* @return The username attribute of the current access token.
* @see Using the Access Token
* from Cognito documentation.
*/
@AnyThread
public String getUsername() {
try {
if (userpoolsLoginKey.equals(mStore.get(PROVIDER_KEY))) {
return userpool.getCurrentUser().getUserId();
}
return null;
} catch (Exception e) {
return null;
}
}

```

### Reproduction steps (if applicable)

_No response_

### Code Snippet

```
CompletableFuture future = new CompletableFuture<>();
Amplify.Auth.getCurrentUser(
user -> future.complete(user.getUsername()),
authException -> future.complete(null)
);
```

Both the user id and the username attributes in AuthUser are the user sub, regardless of how the user logged in.

### 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 from the Auth.getUsername() implementation shown in the issue and inspect how the current Cognito user and access-token username are selected. Verify the behavior for email sign-in against the documented expectation, then add or update the relevant authentication test so completion is demonstrated by returning the email rather than the user sub.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
authentication, mobile-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.