aws-amplify / amplify-flutter

A declarative library with an easy-to-use interface for building Flutter applications on AWS.
https://docs.amplify.aws
Apache License 2.0
1.32k stars 248 forks source link

Wrong information when get current user #2161

Closed AnnaPS closed 2 years ago

AnnaPS commented 2 years ago

Description

I'm trying to get the current user information using the following code

  final _controller = BehaviorSubject<AmplifyUser>();

  Stream<AmplifyUser> get user {
    try {
      Amplify.Hub.listen([HubChannel.Auth], (hubEvent) async {
        if (hubEvent.eventName == 'SIGNED_IN') {
          final user = await _auth.getCurrentUser();
          _controller.add(
            AmplifyUser(id: user.userId, email: user.username),
          );
        } else if (hubEvent.eventName == 'SIGNED_OUT') {
          _controller.add(AmplifyUser.anonymous);
        }
      });

      return _controller.stream;
    } catch (error, stackTrace) {
      Error.throwWithStackTrace(GetCurrentUserFailure(error), stackTrace);
    }
  }

And the debug returns wrong information, basically, set the username (email) field with the id data.

It happens with different apps so I assume is a bug.

Thanks in advance.

Categories

Steps to Reproduce

1- Register a user 2- Login 3- Get current user information

Screenshots

amplify_bug

Platforms

Android Device/Emulator API Level

No response

Environment

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.3.2, on macOS 12.3.1 21E258 darwin-arm, locale en-ES)
[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
[✓] Xcode - develop for iOS and macOS (Xcode 13.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.1)
[✓] VS Code (version 1.67.2)
[✓] Connected device (3 available)
[✓] HTTP Host Availability

Dependencies

Dart SDK 2.18.1
Flutter SDK 3.3.2
flutter_amplify_login 1.0.0+1

dependencies:
- amplify_auth_cognito 0.6.8 [amplify_auth_cognito_android amplify_auth_cognito_ios amplify_core aws_common collection flutter meta plugin_platform_interface]
- amplify_flutter 0.6.8 [amplify_core amplify_datastore_plugin_interface amplify_flutter_android amplify_flutter_ios aws_common collection flutter meta plugin_platform_interface]
- auth_client 0.1.0+1 [amplify_auth_cognito amplify_flutter equatable flutter rxdart]
- bloc 8.1.0 [meta]
- flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine]
- flutter_bloc 8.1.1 [flutter bloc provider]
- flutter_localizations 0.0.0 [flutter intl characters clock collection material_color_utilities meta path vector_math]
- intl 0.17.0 [clock path]

transitive dependencies:
- amplify_auth_cognito_android 0.6.8 [flutter]
- amplify_auth_cognito_ios 0.6.8 [amplify_core flutter]
- amplify_core 0.6.8 [aws_common collection flutter intl json_annotation meta plugin_platform_interface uuid]
- amplify_datastore_plugin_interface 0.6.8 [amplify_core collection flutter meta]
- amplify_flutter_android 0.6.8 [flutter]
- amplify_flutter_ios 0.6.8 [amplify_core flutter]
- async 2.9.0 [collection meta]
- aws_common 0.1.1 [async collection http meta stream_transform uuid]
- characters 1.2.1
- clock 1.1.1
- collection 1.16.0
- crypto 3.0.2 [typed_data]
- equatable 2.0.5 [collection meta]
- http 0.13.5 [async http_parser meta path]
- http_parser 4.0.1 [collection source_span string_scanner typed_data]
- json_annotation 4.7.0 [meta]
- material_color_utilities 0.1.5
- meta 1.8.0
- nested 1.0.0 [flutter]
- path 1.8.2
- plugin_platform_interface 2.1.3 [meta]
- provider 6.0.3 [collection flutter nested]
- rxdart 0.27.5
- sky_engine 0.0.99
- source_span 1.9.0 [collection path term_glyph]
- stream_transform 2.0.0
- string_scanner 1.1.1 [source_span]
- term_glyph 1.2.1
- typed_data 1.3.1 [collection]
- uuid 3.0.6 [crypto]
- vector_math 2.1.2

Device

iPhone 13 Pro

OS

iOS 15.4

Deployment Method

Amplify CLI

CLI Version

7.7.0-flutter-preview.2

Additional Context

No response

Amplify Config

{
    "UserAgent": "aws-amplify-cli/2.0",
    "Version": "1.0",
    "auth": {
        "plugins": {
            "awsCognitoAuthPlugin": {
                "UserAgent": "aws-amplify-cli/0.1.0",
                "Version": "0.1.0",
                "IdentityManager": {
                    "Default": {}
                },
                "CredentialsProvider": {
                    "CognitoIdentity": {
                        "Default": {
                            "PoolId": "eu-west-1:84119d8f-4ffb-4485-b351-efd101c808dc",
                            "Region": "eu-west-1"
                        }
                    }
                },
                "CognitoUserPool": {
                    "Default": {
                        "PoolId": "eu-west-1_CdfJVroIj",
                        "AppClientId": "14pt82m4noiccmf5i7upptk601",
                        "Region": "eu-west-1"
                    }
                },
                "Auth": {
                    "Default": {
                        "authenticationFlowType": "USER_SRP_AUTH",
                        "socialProviders": [],
                        "usernameAttributes": [
                            "EMAIL"
                        ],
                        "signupAttributes": [
                            "EMAIL"
                        ],
                        "passwordProtectionSettings": {
                            "passwordPolicyMinLength": 8,
                            "passwordPolicyCharacters": []
                        },
                        "mfaConfiguration": "OFF",
                        "mfaTypes": [
                            "SMS"
                        ],
                        "verificationMechanisms": [
                            "EMAIL"
                        ]
                    }
                }
            }
        }
    }
}
Jordan-Nelson commented 2 years ago

Hello @AnnaPS - I think this is a duplicate of https://github.com/aws-amplify/amplify-flutter/issues/201.

The "username" field from getCurrentUser unfortunately returns different results for iOS and Android. That issue has some workarounds. You can call fetchUserAttributes, which will also contain the email.

This has been addressed in our latest dev-preview version of auth (available on pub) but it will likely be a bit before it makes it to stable.

Let me know if you believe this issue is not a duplicate of #201. Otherwise I will close this out as a duplicate. Thanks.

AnnaPS commented 2 years ago

@Jordan-Nelson thanks for the quick response. Yes, is duplicated, so I'm going to close it.