skip to Main Content

Introduce the problem

I use an email to log in.

If I log out and try to log in to the same email using Google, the UID of the account changes. I can’t change back to the old UID. How can I provide multiple providers for an account?

What I tried

I asked this question to ChatGPT but it didn’t answer my question. I also googled this problem.

I have read this documentation and used its code, but it didn’t work. Not sure if I’m using its code correctly.

I’ve read this question but it didn’t help me.

A minimal, reproducible example

Future<void> signInWithEmailAndPassword(String email, String password) async {
  try {
    await firebaseAuth.signInWithEmailAndPassword(email: email, password: password);
    final credential = EmailAuthProvider.credential(email: email, password: password);
    await FirebaseAuth.instance.currentUser?.linkWithCredential(credential);
  } on FirebaseAuthException catch (e) {
    throw FirebaseAuthException(code: e.code, message: e.message);
  }
}

2

Answers


  1. You should be able to achieve this via the Firebase Console. The Firebase Authentication Settings tab allows you to link accounts with the same email.

    https://console.firebase.google.com/u/0/project/yourprojectname/authentication/settings

    Login or Signup to reply.
  2. Account linking works by first having a currently signed in user, and then linking an additional provider to it. In steps:

    1. Sign in with the existing provider.
    2. Check that currentUser isn’t null.
    3. Create credentials for the additional provider
    4. Link the additional provider to the existing account by calling linkWithCredential.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search