强制令牌刷新但令牌仍然已过期?

时间:2017-08-29 13:23:53

标签: javascript node.js firebase firebase-authentication firebase-admin

var app = angular.module('app', ['firebase']);
const setAppCookie = () => firebase.auth().currentUser.getToken(true).then(token => {
    Cookies.set('token', token, {
        domain: window.location.hostname,
        expire: 1 / 24,
        path: '/',
        secure: true
    });
});
const unsetAppCookie = () => Cookies.remove('token', {
    domain: window.location.hostname,
    path: '/',
});
app.factory("Auth", ["$firebaseAuth", function ($firebaseAuth) {
    return $firebaseAuth();
}]);
app.controller("ctrlHead", ["$scope", "Auth", "$window", function ($scope, Auth, $window) {
    $scope.auth = Auth;
    $scope.auth.$onAuthStateChanged(function (firebaseUser) {
        if (firebaseUser) {
            setAppCookie();
            localStorage.setItem("authenticated", JSON.stringify("yay!"));
        } else {
            localStorage.setItem("authenticated", JSON.stringify(null));
        }
    });
    $scope.authenticated = JSON.parse(localStorage.getItem("authenticated"));
}]);

以下是我使用Firebase ^

登录后设置令牌的代码

以下是检查服务器上令牌的代码:

router.get('/page', function(req, res, next) {
    global.page_name = current;

    const { token } = req.cookies;

    if (!token || token == undefined) {
            global.page_name = "...";

            res.redirect("/");
    }
    else {
        admin.auth().verifyIdToken(token)
        .then(decodedToken => {
        }).catch(err => {
            console.log(err);
                global.page_name = "...";

                res.redirect("/");
        });
    }  
});

虽然我将令牌设置为强制刷新,但我无法登录并始终收到以下错误:

{错误:Firebase ID令牌已过期。从您的客户端应用中获取新的令牌,然后重试。有关如何检索ID令牌的详细信息,请参阅https://firebase.google.com/docs/auth/admin/verify-id-tokens

发生了什么事?我做错了什么?

0 个答案:

没有答案
相关问题