Angularjs $firebaseAuth在刷新后将我注销(facebook)

Angularjs $firebaseAuth在刷新后将我注销(facebook),angularjs,facebook,angularfire,firebase-security,Angularjs,Facebook,Angularfire,Firebase Security,我使用$firebaseAuth来控制应用程序的登录部分。以前一切正常,但现在,刷新后,我立即注销 我路线的一部分: }).when("/login/", { templateUrl:"partials/login.html", controller:"tiki.controller.login" }).when("/settings/profile/", { templateUrl:"partials/settings.profile.html",

我使用$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()

})
function authenticate(){

    return {"currentAuth": ["firebaseAuth", function(firebaseAuth) {

        console.log(firebaseAuth.requireAuth())
        return firebaseAuth.requireAuth();

    }]}     

}
authenticate()函数

}).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()

})
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/");

        }

    });

}]);
'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

    }

}])
为了实现完整性,我的firebaseAuth.js服务:

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/");

        }

    });

}]);
'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"
这仅在刷新所有页面时发生。如果我不刷新,则验证工作正常

有什么想法吗


thx,

不确定是否是您的问题,但来自:

可选设置

authWithOAuthPopup()和authWithOAuthRedirect()采用可选的第三个参数,该参数是包含以下任何设置的对象:

记住
如果未指定或未设置为默认值,则会话将在您在Firebase仪表板的“登录和身份验证”选项卡中配置的时间内保持不变。若要将持久性限制为当前窗口的生存期,请将其设置为“仅会话”值none将根本不会保留身份验证数据,并将在页面关闭后立即结束身份验证。


我不知道页面刷新是否算作关闭页面,但可能值得检查Login和Auth中的值,以确保它没有设置为不可靠的值,我刚刚测试过,它会很高兴让您将其设置为0

Rick,谢谢您的回答,但它似乎已经解决了。我没有对我的代码做任何更改,所以我猜这是firebase的问题。我希望这个链接仍然有效。这不是唯一一个链接断开的类似指南,所以我猜他们的文档一定已经更新了。