Firebase 身份验证在密码重置后不更新

Firebase Auth not updating once password reset

提问人:dmo 提问时间:7/10/2015 最后编辑:dmo 更新时间:7/20/2015 访问量:737

问:

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

我正在寻找强制用户重置密码的布尔值。一旦用户执行了此过程并重置,仍然存在 .trueauth.password.isTemporaryPasswordauth.password.isTemporaryPasswordtrue

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

登录:

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

AngularJS 身份验证 Firebase

评论

1赞 Frank van Puffelen 7/10/2015
请不要描述您的代码,而是包含一个将问题重现到您的问题中的最小代码片段。到那时,帮助您会容易得多。(见 stackoverflow.com/help/mcve)

答:

0赞 bmc 7/20/2015 #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 {

    }
});