angularjs – 一旦密码重置,Firebase Auth不会更新

前端之家收集整理的这篇文章主要介绍了angularjs – 一旦密码重置,Firebase Auth不会更新前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
一旦第一次加载Firebase Auth对象,我似乎无法弄清楚如何重置它.

我在auth.password.isTemporaryPassword中寻找bool true值,强​​制用户重置密码.一旦用户执行了此过程并重置,则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保持为真,直到我再次登录用户,这似乎是hacky.

解决方法

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

    }
});

猜你在找的Angularjs相关文章