【发布时间】:2015-03-14 08:09:08
【问题描述】:
我正在使用 $firebaseAuth 来控制我的应用程序的登录部分。以前一切正常,但现在刷新后,我立即退出。
我的部分路线:
}).when("/login/", {
templateUrl:"partials/login.html",
controller:"tiki.controller.login"
}).when("/settings/profile/", {
templateUrl:"partials/settings.profile.html",
controller:"tiki.controller.settings.profile",
resolve:authenticate()
})
authenticate() 函数:
function authenticate(){
return {"currentAuth": ["firebaseAuth", function(firebaseAuth) {
console.log(firebaseAuth.requireAuth())
return firebaseAuth.requireAuth();
}]}
}
捕获路由更改错误的 .run() 块:
angular.module('tiki').run(["$rootScope", "$location", function($rootScope, $location) {
$rootScope.$on("$routeChangeError", function(event, next, previous, error) {
// We can catch the error thrown when the $requireAuth promise is rejected
// and redirect the user back to the home page
if (error === "AUTH_REQUIRED") {
$location.path("/login/");
}
});
}]);
为了完整起见,我的 firebaseAuth.js 服务:
'use strict';
/* Services */
angular.module("tiki").factory("firebaseAuth", ["$firebaseAuth", function($firebaseAuth){
var ref = new Firebase("https://blistering-xxx.firebaseio.com/");
if(ref){
var service = $firebaseAuth(ref)
}
function loginFacebook(){
return service.$authWithOAuthPopup("facebook")
}
function logOut(){
service.$unauth()
}
function getState(){
var state = service.$getAuth()
if(state){
return state
}
}
function getUserName(){
if(getState()){
return getState().facebook.displayName
}
}
function requireAuth(){
return service.$requireAuth()
}
function service(){
return service
}
return {
loginFacebook:loginFacebook,
logOut:logOut,
getState:getState,
getUserName,
requireAuth:requireAuth,
service:service
}
}])
当我在 /settings/profile/ 中刷新时,我会注销并返回到 /login/。
authenticate() 函数中的 console.log() 返回:
status: 2
value:"AUTH_REQUIRED"
这只发生在所有页面的刷新时。如果我不刷新,则身份验证工作正常。
有什么想法吗?
谢谢,
【问题讨论】:
标签: angularjs facebook angularfire firebase-security