javascript - firebase sendEmailVerification 在不存在的电子邮件地址上不会给出错误

标签 javascript firebase firebase-authentication

我正在使用 Firebase Auth 为我的 React 应用开发身份验证系统。当用户注册时,firebase auth 会注册用户 (createUserWithEmailAndPassword) 并返回一个将 auth.uid 和 auth.emailVerified 设置为“false”的 promise 。这很好。

然后我使用 sendEmailVerification() 方法,以便可以验证电子邮件地址。我已经测试了代码,对于“有效”和“现有”电子邮件地址来说它可以正常工作。 “catch”确实会按预期给出重复电子邮件地址的错误。问题是,它不会发送不存在的电子邮件(我认为这是正确的行为),但它应该给出一个错误(这样我可以向用户显示),但它没有。

有人可以解释一下为什么我没有收到“不存在的电子邮件地址”错误吗?

export const unpSignUp = (newUser) => {
    console.log("newUser", newUser);
    return (dispatch, getState, { getFirebase, getFirestore }) => {
        const firebase = getFirebase();
        const firestore = getFirestore();
        firebase.auth().createUserWithEmailAndPassword(
        newUser.unp_a05_email,
        newUser.unp_a10_password
        )
        .then((response) => {
        return firestore
            .collection("unps")
            .doc(response.user.uid)
            .set({
                unp_a02_surname: newUser.unp_a02_surname,
                unp_a03_name: newUser.unp_a03_name,
                unp_a06_verify_email_sent_datetime: null,
                unp_a07_email_verified_on_datetime: null,
                unp_a18_acc_created_on_datetime: moment().format("YYYY MM DD HH:mm:ss"),
            });
        })
            .then((response) => {
            console.log("SIGNUP SUCCESS ", response);
            // user has been signed up, next step is to send verification email
            dispatch({ type: SIGNUP_SUCCESS })
        })
        .then(() => {
            // user has been signed up, next step is to send verification email
            console.log('send email adr verification')
            return firebase.auth().currentUser.sendEmailVerification()
        })
        .then( (response) => {
            console.log("Verification email sent", response);
            const user = firebase.auth().currentUser
            console.log('current user', user)
            const unp = firestore.collection("unps").doc(user.uid);
            return unp.update({
            unp_a06_verify_email_sent_datetime: moment().format("YYYY MM DD HH:mm:ss"),
            })
        })
        .then( () => {
            console.log(`unp_a06_verify_email_sent_datetime update to ${moment().format("YYYY MM DD HH:mm:ss")} `)
        })
        .catch((error) => {
            console.log("SIGNUP ERROR", error);
            console.log("SIGNUP ERROR CODE", error.code);
            console.log("SIGNUP ERROR MESAGE", error.message);
            dispatch({ type: SIGNUP_ERROR, error });
        });
    };
};

最佳答案

来自firebase reference ,

sendEmailVerification的返回类型是 Promise<void> - 它不会告诉您在错误电子邮件或失败/退回邮件的情况下发送的任何错误代码。它提到的错误代码是关于 actionCodeSettings

If the actionCodeSettings is not specified, no URL is appended to the action URL. The state URL provided must belong to a domain that is whitelisted by the developer in the console. Otherwise an error will be thrown.

因此无法检查它是否是有效的电子邮件 ID。 (这是预期行为,因为接收邮件服务器有时可能会关闭,因此存在重试退回邮件的概念)

关于javascript - firebase sendEmailVerification 在不存在的电子邮件地址上不会给出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62374782/

相关文章:

javascript - 在 Javascript 中创建表

javascript - 如何获取php var OpenWeatherMap中第二行js数据

Firebase 返回内部服务器错误

swift - 如何检测用户是否已从 Firebase 身份验证中删除?

javascript - 当 css3 转换不可用时自动回退到 jquery (Internet Explorer)

Firefox 中的 JQUERY Galleria css 位置对齐问题。在 Chrome 中运行良好

firebase - 尝试使用.createUserWithEmailAndPassword时为类“The getter '定义的' isn' uid 'AuthResult' t

firebase - Firebase Analytics 仪表板和 BigQuery 导出之间的 "active users metric"差异

firebase - 如何从测试中访问 Firebase Flutter 插件?

node.js - 在哪里可以找到包含 revokeRefreshTokens 方法的 firebase-admin 包?