New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Amplify.Auth.getCurrentUser() return different platform results when using email based auth #201
Comments
Current workaround to get email on both platforms. final authState = await Amplify.Auth.fetchAuthSession(
options: CognitoSessionOptions(getAWSCredentials: true))
as CognitoAuthSession;
if (authState.isSignedIn) {
final claims = _parseJwt(authState.userPoolTokens.idToken);
final email = claims['email'] as String;
}
|
@kjones I noticed this as well and thank you for the workaround! |
@kjones yes, you are right. However, it seems to be problem of the native libraries, they have different implementation on that part. Just to note, iOS implementation is correct as the username has to be different from the email, the mistake is on the Android native library. |
@kjones We have an API that should allow you to fetch the user attributes, so parsing the JWT shouldn't be necessary: await Amplify.Auth.fetchUserAttributes() |
The following code correctly obtains user's email in both iOS and Android: |
It looks like this is a result of an issue in the amplify-ios library used by amplify-flutter when targeting iOS. There is an issue open in the amplify-ios repo currently here: aws-amplify/amplify-swift#1255. I will follow up with the team and see if this is being looked into. As several others have already noted, you can get the email address consistently on both platforms using |
Anybody know how to do the opposite, get the username on both instead of email? |
Does this happen as well with userId? I do not have the means to test it. I am using it to store user-related data, and now I am worried... Should I use another method to say, for example, that a note has been created by a user? I am using this value: |
@guplem - The user ID will always be the Cognito identifier. It seems there is a discrepancy around username in some cases, but the user ID will not be affected in the same way. |
I'd like to know this as well. Currently on iOS you can get the user's username with:
But on Android it returns the email address if the user signed in with email. |
Hello everyone - We have recently released a new developer preview version of the Auth category (amplify_flutter v1.0.0-next.0). This new version is a full re-write of the auth category in dart, and it supports Mobile, Desktop, and Web. This issue is addressed in this new version. You can read more about the developer preview release in the blog post and docs. I will update this issue again once this new version is out of developer preview. Let me know if you have any questions! |
This issue has been addressed in v1.0.0 of Amplify Flutter, which is now stable. This release also includes web and desktop support for Auth, API, Analytics, and Storage. You can see the list of new features and bug fixes in the release notes, and see more details on how to migrate in the upgrade guide. |
Hello. I am using Amplify 1.2.0 and this is still an issue. AuthUser returned by Amplify.Auth.getCurrentUser() has the user id as userId and username. I am using email based authentication on Android. |
Still have this issue. Getting id on iOS instead of email. Using v1.3.0. |
Hi @alterhuman, please see my comment here and let me know if that resolves your issue. When an issue is closed, it's hard for us to gain visibility into comments which are added. Please always feel free to open a new issue so that we can better assist you. |
When adding Cognito auth to a project, if email based sign-in is chosen (might apply to phone number also) then
Amplify.Auth.getCurrentUser()
return differentAuthUser
results between Android and iOS. Android returns withAuthUser.username
set to the email address but iOS appears to return the Cognito userSub value.To Reproduce
amplify add auth
) to use email based authentication.Amplify.Auth.getCurrentUser()
.Expected behavior
Amplify.Auth.getCurrentUser()
should return the same results on both Android and iOS.Platform
Amplify Flutter 0.0.1-dev.3
[x] Android
[x] iOS
The text was updated successfully, but these errors were encountered: