0

I am trying to link more account with the same credentials (Email and Password, Google and Github), but when i try to log in with github i get this error:

FirebaseError: Firebase: Error (auth/account-exists-with-different-credential).

The Google authentication is working. The situation on database is shown below:

image

Here i call the functions in the authStore.js file (those functions are shown in the next code block).

async function loginGoogle() {
        await authHandlers
            .loginGoogle()
            .then(() => {
                goto('/');
            })
            .catch((error) => {
                if (error.code === 'auth/account-exists-with-different-credential') {
                    alert('You have already signed up with a different auth provider for that email.');
                } else {
                    console.error(error);
                }
            });
    }

    async function loginGithub() {
        await authHandlers
            .loginGithub()
            .then(() => {
                goto('/');
            })
            .catch((error) => {
                if (error.code === 'auth/account-exists-with-different-credential') {
                    console.error(error);
                    alert('You have already signed up with a different auth provider for that email.');
                } else {
                    console.error(error);
                }
            });
    }

The code below is where i make the calls to the firebase.

export const authHandlers = {
    login: async (email, password) => {
        await signInWithEmailAndPassword(auth, email, password);
    },
    signup: async (email, password, username) => {
        const { user } = await createUserWithEmailAndPassword(auth, email, password);
        await updateProfile(user, {
            displayName: username
        });
        sendEmailVerification(user)
            .then(() => {
                console.log('Email sent');
            })
            .catch((error) => {
                console.log(error);
            });
    },
    logout: async () => {
        await signOut(auth);
    },
    loginGoogle: async () => {
        await signInWithPopup(auth, new GoogleAuthProvider());
    },
    loginGithub: async () => {
        await signInWithPopup(auth, new GithubAuthProvider());
    },
Ahmed Sbai
  • 10,695
  • 9
  • 19
  • 38

1 Answers1

0

The default behavior for Firebase Authentication is that it only allows a single account for each email address.

If you want to link the multiple sign-in methods to the same account in Firebase, have a look at Firebase JS API auth - account-exists-with-different-credential

If you want these sign-in methods to become separate accounts, you can enable Create multiple accounts for each identity provider under the Authentication settings in the Firebase console.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807