【问题标题】:Firebase Auth not updating once password resetFirebase Auth 在密码重置后不会更新
【发布时间】:2015-07-09 20:15:19
【问题描述】:

我似乎不太明白如何在 Firebase Auth 对象首次加载后重置它。

我正在寻找 auth.password.isTemporaryPassword 中的 bool true 值,它会强制用户重置密码。一旦用户执行此过程并重置,auth.password.isTemporaryPassword 将保持为true

我发现解决此问题的唯一方法是注销用户并再次登录,这会刷新身份验证对象。

登录:

var ref = new Firebase(environment);

$firebaseAuth(ref)
.$authWithPassword({
     email: email,
     password: password
},sessionObj)
.then(function(authData) {
    if (password.isTemporaryPassword === true) {
        $state.go('resetpassword');
    }
})
.catch(function(error) {
    deferred.reject(error);
});

重置密码:

$scope.reset.oldPassword         =  "oldPass";
$scope.reset.newPassword         =  "newPass";
$scope.reset.email              =   "usermail";

ref.changePassword($scope.reset, function(err) {
    if(err) {
         ...
    }
    else {
        $state.go('home')
    }
})

password.isTemporaryPassword 仍然是true,直到我再次登录用户,这看起来很老套。

【问题讨论】:

  • 请不要描述您的代码,而是在您的问题中包含一个最小的 sn-p 来重现问题。到时候帮助你会容易很多。 (见stackoverflow.com/help/mcve

标签: angularjs authentication firebase


【解决方案1】:

您应该能够使用onAuth 函数来监听身份验证状态的变化:

ref.onAuth(function(authData) {

    //user authenticated & needs to change her password
    if(authData && authData.password.isTemporaryPassword) {
        $state.go('resetpassword');
    }

    //else user is logged in with valid password
    else if(authData) {

    }

    //else user is logged out
    else {

    }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-14
    • 2014-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-24
    • 2013-01-29
    • 2019-06-28
    相关资源
    最近更新 更多