首页 文章

Firebase v3密码验证 - 触发/防火验证电子邮件?

提问于
浏览
0

对于Firebase上托管的Web应用程序,我想通过向他们发送验证链接来验证新用户 . 我浏览了文档Create custom email action handlers,并配置了我的自定义域并使密码验证工作正常 .

那么,我该如何触发密码验证呢?我如何获得oobCode和apiKey参数?我正在注册一个新用户,我的auth listener页面上没有任何反应?

var getArg = getArg();
var mode = getArg['mode'];
var oobCode = getArg['oobCode'];
var apiKey = getArg['apiKey'];

console.log(mode, oobCode, apiKey);

switch (mode) {
    case 'resetPassword':
        console.log('Password Request Fired');
        break;
    case 'recoverEmail':
        console.log('Recover Email Fired');
        break;
    case 'verifyEmail':
        console.log('Verify Email Fired');
        break;
}

//Thanks Geoffrey Crofte
function getArg(param) {
    var vars = {};
    window.location.href.replace(location.hash, '').replace(
        /[?&]+([^=&]+)=?([^&]*)?/gi, // regexp
        function(m, key, value) { // callback
            vars[key] = value !== undefined ? value : '';
        }
    );

    if (param) {
        return vars[param] ? vars[param] : null;
    }
    return vars;
}

1 回答

  • 1

    firebase.auth().currentUser.sendEmailVerification()modeoobCodeapiKey 变量发送到登录用户的电子邮件地址 . 在验证之前,可以通过阅读 currentUser.emailVerified 属性将已登录的用户标识为未验证 . 用户打开电子邮件并单击验证链接,该链接将调用HTTP会话到您的auth侦听器页面,并将这些变量作为URL中的参数显示 .

    在原始帖子(或您自己的帖子)中使用 getArg() 方法将浏览器 window.location (当前网址/ URL)中的参数解析为您的身份验证监听器页面的JavaScript中的变量 .

    firebase.auth().currentUser.sendEmailVerification()
    //checks if signed in user is verified, if not tell them to check email
    firebase.auth().currentUser.emailVerified; //false now so handle user experience appropriately until verified
    

    Official Web Methods Reference Index很有用 . 其他一些相关的方法(都可以)如下所示:

    //updates email of signed in user
    -> firebase.auth().currentUser.updateEmail(newEmail)
    
    //updates password of signed in user
    -> firebase.auth().currentUser.updatePassword(newPassword)
    -> firebase.auth().sendPasswordResetEmail(email)
    
    //deletes auth account of signed in user
    -> firebase.auth().currentUser.delete()
    

相关问题