skip to Main Content

I have a sign in with Google:[email protected]

then create an account with the same email:[email protected]

There is a problem with two different providers

  1. Sign in with Google (same Gmail)
  2. Sign in with Email (same Gmail)

How Can I handle these two (When I delete the google sign-in account from Firebase Console. I can create an account with that email) Otherwise I can’t create an account with that email and also can’t sign in.

I learning Firebase Auth with https://github.com/gladly-team/next-firebase-auth

2

Answers


  1. If you first sign in with Google using "[email protected]", it means a user will be created using this particular email address. If you try to sign in with any other provider or with an email and password using the same email address, you’ll get an error message that says that the user already exists. And it makes sense since you have already used that email for a user before.

    There are two ways in which you can solve this problem. When you get such an error, you can check the provider used to create the account, and notify the user to use it. For example, if the user signs in with Google and tries to authenticate with email and password right after that, display a message to the user in which you should say that the user already exists, and should use the authentication provider which was selected to create the account in the first place, in this case, Google.

    The second option would be to allow the user to have multiple accounts using the same email address with different authentication providers. This option can be enabled directly in the Firebase Console, in the Authentication section.

    So it’s up to you to decide which option works better for your project.

    Login or Signup to reply.
  2. The simple Solution is to enable multiple account an email.
    enter image description here

    Or —————-

    You Link the account.

    This is an example when there is a facebook account with a certain email
    and you want to use that same email to sign in with Email and password or gmail, if those two emails are not linked different provider error will be thrown. check here for more

     export function linkFaceBookAccount(authContext?: AuthContextType, notificationContext?: NotificationContextType, history?: History.History) {
    const provider = new FacebookAuthProvider(); // create a provider
    
    linkWithPopup(auth.currentUser as User, provider).then((result) => {
        // This gives you a Google Access Token. You can use it to access the Google API.
        // const credential = FacebookAuthProvider.credentialFromResult(result);
        // const token = credential?.accessToken;
        // The signed-in user info.
        const user = result.user;
        saveUserToLocalStorage(user);
        authContext?.loadUserToState(user);
    
        notificationContext?.addNotification({
            message: `This email's (${auth.currentUser?.email}) account has been successful linked with your facebook account`,
            title: "Link successful",
            notificationType: "SUCCESS",
            positiveActionText: "continue",
            positiveAction: () => {
                history?.push("/")
            }
        })
    }).catch((error) => {
    
        const email = error.customData?.email;
        const errorCode = error.code;
        const duplicateAccount = errorCode === "auth/account-exists-with-different-credential";
        notificationContext?.addNotification({
            message: errorFirebase(error, email),
            title: "Linking Error",
            notificationType: "WARNING",
            positiveActionText: duplicateAccount ? "Link" : "ok",
            negativeActionText: duplicateAccount ? "cancel" : undefined,
            code: errorCode,
            positiveAction: () => {
                if (duplicateAccount) {
                    duplicateAccountLinking(email, "FACEBOOK", history);
                }
            }
        })
    });}
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search