在我使用Firebase A身份验证的Web应用程序中,我提供了Google登录和电子邮件密码登录两个选项。直到昨天(2023年10月21日),这两个选项都正常工作
我的用户能够使用电子邮件(比如说email protected(https://stackoverflow.com/cdn-cgi/l/email-protection))和密码注册,并使用他们的凭据登录,当他们试图使用相同的谷歌电子邮件(email protected(https://stackoverflow.com/cdn-cgi/l/email-protection))登录谷歌时,Firebase不知何故能够自动合并这些帐户,而不会删除我的电子邮件/密码凭据。
现在发生的情况是,当我尝试使用[[email protected]](https://stackoverflow.com/cdn-cgi/l/email-protection)
登录Google时,它只是覆盖了电子邮件密码凭据,因为当我尝试使用电子邮件密码身份验证时,它会抛出这个错误代码auth/wrong-password
。
这是firebase刚刚用来合并我的帐户时的图片,但现在没有发生。你可以看到2023年8月5日的帐户,其中谷歌和电子邮件的徽标显示为x1c 0d1x
这是我的一些验证码。
注册
const signUpWithEmailAndPassword = async (email, password) => {
try {
const authInstance = getAuth();
return await createUserWithEmailAndPassword(
authInstance,
email,
password
);
} catch (err) {
console.log('err', err);
if (err.code === 'auth/invalid-email') {
throw new Error('Email address is not valid');
} else if (err.code === 'auth/email-already-in-use') {
throw new Error('Email already existed');
} else if (err.code === 'auth/network-request-failed') {
throw new Error('Please check your connection');
} else {
throw new Error(
'An error occurred during sign up. Please try again later.'
);
}
}
};
字符串
使用电子邮件/密码登录
const signInWithEmailAndPassword = async (email, password) => {
try {
const authInstance = getAuth();
console.log('Auth instance', authInstance);
return await emailPasswordSignIn(authInstance, email, password);
} catch (err) {
console.log(err.code);
if (
err.code === 'auth/user-not-found' ||
err.code === 'auth/wrong-password'
) {
throw new Error(
'Incorrect email or password. Please try again.'
);
} else if (err.code === 'auth/network-request-failed') {
throw new Error('Please check your connection');
} else if (err.code === 'auth/invalid-email') {
throw new Error('Please provide valid email');
} else {
throw new Error(
'An error occurred during sign in. Please try again later.'
);
}
}
};
型
使用Google登录
const signInWithGoogle = async () => {
try {
console.log('Google sign-in started');
return await signInWithPopup(auth, googleProvider);
} catch (err) {
console.error(err);
throw err;
}
};
型
我想我的代码没有更改,请帮助我,谢谢
1条答案
按热度按时间bjg7j2ky1#
我已经提供了谷歌登录和电子邮件密码登录的选项。
您所体验到的是从一开始就默认的行为,这意味着当用户使用Google帐户登录时,在使用电子邮件和密码成功进行身份验证后,Firebase身份验证中的数据总是被覆盖。这意味着Google凭据仍然是默认凭据。这是因为一个明显的原因,Google帐户是更受信任的来源,因此这种行为。
为了解决你的问题,你需要在一个单一的link those 2 accounts,基于该电子邮件地址。就是这样。