我使用AngularJS和Firebase对应用程序中的用户进行身份验证。登录过程就像一种魅力,但是当我刷新页面时,它会忘记auth状态,我需要再次登录。我怎么才能让它“粘住”?守则如下:
.factory('loginService', ['$firebaseSimpleLogin', '$location', '$rootScope', 'firebaseurl',
function($firebaseSimpleLogin, $location, $rootScope, firebaseurl) {
return {
login: function(email, pass, redirect, callback) {
var dataRef = new Firebase(firebaseurl);
$rootScope.loginObj = $firebaseSimpleLogin(dataRef);
$rootScope.loginObj.$login('password', {
email: email,
password: pass,
rememberMe: true
}).then(function(user) {
console.log('Logged in as: ', user.uid);
}, function(error) {
console.error('Login failed: ', error);
});
},
logout: function(redirectPath) {
$rootScope.loginObj.$logout();
if(redirectPath) {
$location.path(redirectPath);
}
}
}
}])发布于 2014-01-17 16:24:48
我使用angularfire种子https://github.com/firebase/angularFire-seed/添加了以下服务:
.run(['loginService', '$rootScope', 'FBURL', function(loginService, $rootScope, FBURL) {
// establish authentication
$rootScope.auth = loginService.init('/admin/signin');
$rootScope.FBURL = FBURL;
}])才能让它发挥作用。
https://stackoverflow.com/questions/21189651
复制相似问题