我尝试用相同的凭据链接更多帐户(电子邮件和密码,谷歌和Github),但当我尝试用github登录时,我得到这个错误:
Firebase错误:Firebase:错误(身份验证/帐户存在,但凭据不同)。
Google认证工作正常,数据库情况如下:
image
这里我调用authStore.js文件中的函数(这些函数在下一个代码块中显示)。
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);
}
});
}
下面的代码是我调用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());
},
1条答案
按热度按时间omqzjyyz1#
Firebase身份验证的默认行为是,它只允许每个电子邮件地址使用一个帐户。
如果要将多个登录方法链接到Firebase中的同一帐户,请查看Firebase JS API auth - account-exists-with-different-credential
如果希望这些登录方法成为单独的帐户,可以在Firebase控制台的Authentication settings下启用为每个身份提供者创建多个帐户。