我试图发现当有人注册到我所填写的表格但该电子邮件地址已被使用时,如何使声明出现。我正在使用Firebase。我不熟悉fetchSignInForEmail,并且想知道如何使用和实现它。
我认为我可以使用if语句
if(email exists) {
push firebase user to directed page
} else {
statement.style.display === block
}
我也很好奇如何使用密码。
谢谢
答案 0 :(得分:0)
收听该错误。但是,我更喜欢合并帐户并让用户登录。下面是一个示例片段。 I've got this done for you,前提是您要允许电子邮件链接身份验证(不需要密码)。 Firebase还提供了一种预卷式产品,它支持密码和联合身份验证/ oAuth(Twitter,Facebook等)。
} catch (error) {
if(error.code === "auth/email-already-in-use"){
// REMEMBER AUTH CURRENT USER OBJECT
previousUser = firebase.auth().currentUser;
// WE MUST HANDLE DB READ AND DELETE WHILE SIGNED IN AS PREVIOUS USER PER FIRESTORE SECURITY RULES
if(localUserDoc){
if(localUserDoc.data().apples){
apples = localUserDoc.data().apples;
}
}
//DELETE CURRENT USER RECORD WHILE STILL SIGNED IN
await firebase.firestore().collection("users").doc(previousUser.uid).delete();
// CLEAN UP DONE. NOW SIGN IN USING EMAIL LINK CREDENTIAL
try {
var firebaseUserObj = await firebase.auth().signInAndRetrieveDataWithCredential(credential);
// FIRESTORE USER RECORD FOR EMAIL LINK USER WAS CREATED WHEN THEY ADDED APPLE TO CART
try {
var doc = await firebase.firestore().collection("users").doc(firebaseUserObj.user.uid).get();
if (doc.exists) {
if(doc.data().apples){
apples = apples + doc.data().apples;
}
}
await firebase.firestore().collection("users").doc(firebaseUserObj.user.uid).update({
apples: apples
});
} catch(error) {
console.log("Error getting document:", error);
}
previousUser.delete();
} catch (error) {
console.log(".signInWithCredential err ", error);
}
}
}