密码重置后Firebase Auth不会更新

时间:2015-07-09 20:15:20

标签: angularjs authentication firebase

第一次加载Firebase Auth对象时,我似乎无法弄清楚如何重置Firebase Auth对象。

我在true中寻找强制用户重置密码的bool auth.password.isTemporaryPassword值。用户完成此步骤并重置后,auth.password.isTemporaryPassword仍为true

我找到的唯一方法是将用户注销并再次登录,刷新auth对象。

登录:

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,直到我再次登录该用户,这似乎很麻烦。

1 个答案:

答案 0 :(得分:0)

您应该能够使用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 {

    }
});
相关问题