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:
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());
},