flutterfire icon indicating copy to clipboard operation
flutterfire copied to clipboard

[firebase_auth ^0.15.4] <Multiple accounts per email address>

Open kingdg25 opened this issue 6 years ago • 4 comments

Screenshot from 2020-02-07 13-16-56

In firebase authentication Allow creation of multiple accounts with the same email address

  GoogleSignInAccount googleUser = await googleSignIn.signIn();
  print(googleUser.authentication);
  GoogleSignInAuthentication googleAuth = await googleUser.authentication;
  print(googleAuth.idToken);
  final AuthCredential credential = GoogleAuthProvider.getCredential(
    accessToken: googleAuth.accessToken,
    idToken: googleAuth.idToken,
  );
  print(credential);
  FirebaseUser firebaseUser =
  (await firebaseAuth.signInWithCredential(credential)).user;
  print("=====firebaseUser");
  print(firebaseUser);
  print(firebaseUser.email);

After logging in, getting the email(even others functions like displayName, photoUrl) using the FireBaseUser instance(firebase.email) returns null.

here is the output/print: Screenshot from 2020-02-07 13-32-29

But choosing back the Prevent creation of multiple accounts with the same email address in authentication advance settings: Screenshot from 2020-02-07 13-25-53

No errors but returning the expected email address.

PS. that email address was used in different provider(like facebook login)

kingdg25 avatar Feb 07 '20 05:02 kingdg25

Hi @kingdg25 can you please provide your flutter doctor -v , your flutter run --verbose and your pubspec.yaml Thank you

iapicca avatar Mar 06 '20 13:03 iapicca

@kingdg25 May be a bug, try to get email by

final email = firebaseUser.email ?? firebaseUser.providerData.firstOrNullWhere((e) => e.email != null)?.email;

firstOrNullWhere from dartx: https://pub.dev/packages/dartx or write by your self.

hsangtini avatar Mar 09 '20 05:03 hsangtini

@kingdg25 May be a bug, try to get email by

final email = firebaseUser.email ?? firebaseUser.providerData.firstOrNullWhere((e) => e.email != null)?.email;

firstOrNullWhere from dartx: https://pub.dev/packages/dartx or write by your self.

Thanks for this solution.

arpitjacob avatar May 11 '20 09:05 arpitjacob

Hi @kingdg25

I have tested this using the WIP roadmap version as per below, and can confirm that the information required can be found in providerData. It looks like the implementation is the same for the version you are using as per your comment above.

final GoogleSignInAccount googleUser = await GoogleSignIn().signIn();
GoogleSignInAuthentication googleAuth = await googleUser.authentication;

final AuthCredential credential = GoogleAuthProvider.credential(
  accessToken: googleAuth.accessToken,
   idToken: googleAuth.idToken,
);

final UserCredential firebaseUser = await FirebaseAuth.instance.signInWithCredential(credential);

print(firebaseUser.user);

User(displayName: Greg, email: null, emailVerified: false, isAnonymous: false, metadata: UserMetadata(creationTime: 2020-07-14 12:06:24.661, lastSignInTime: 2020-07-14 12:54:50.509), phoneNumber: null, photoURL: https://lh3.googleusercontent.com/a-/*****, providerData, [UserInfo(displayName: Greg, email: g****@****.com, phoneNumber: null, providerId: google.com, uid: ******)], refreshToken: , tenantId: null, uid: *******)

greghesp avatar Jul 14 '20 08:07 greghesp