一旦第一次加载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') } })
解决方法
您应该能够使用
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 { } });