Javascript 如何从客户端扩展firebase身份验证登录会话?

Javascript 如何从客户端扩展firebase身份验证登录会话?,javascript,firebase,firebase-authentication,Javascript,Firebase,Firebase Authentication,问题在标题中。我做了一些研究,但似乎找不到在使用firebase身份验证时延长登录会话寿命的解决方案 目前,我有一个文件可以让用户从前端登录。使用Firebase身份验证登录后,我将Firebase id令牌传递给服务器: //[index.php] auth.onAuthStateChanged(function(user) { if (user) { //Retrieve the firebase id token user.getIdToken

问题在标题中。我做了一些研究,但似乎找不到在使用firebase身份验证时延长登录会话寿命的解决方案

目前,我有一个文件可以让用户从前端登录。使用Firebase身份验证登录后,我将Firebase id令牌传递给服务器:

//[index.php]
 auth.onAuthStateChanged(function(user) {

    if (user) {

        //Retrieve the firebase id token
        user.getIdToken().then((idToken) => {

            //Send the idToken to the server
            sendIdTokenToServer();

        });

    } else {

        //The user is logged out, redirect to login page

    }

});
从服务器端,我验证firebase id令牌,并将其分配给
$\u会话['firsebase\u id\u token']
,前提是该令牌有效

//[server.php]
//Pseudo verifying the token, if the token is valid, record it
if (verifyToken($token)) $_SESSION['firebase_id_token'] = $token;
现在,从这一点开始,我试图在从服务器端处理任何事情之前验证令牌。例如:

//[test.php]
//Before processing anything, validate the token
if (verifyToken($_SESSION['firebase_id_token'])) {

    //Perform an action because the user is still logged in

} else {

    //Redirect the user to login page because they are logged out/the token cannot be verified

}
我不确定这是解决问题的正确方法(因此请建议正确的方法),它们正是我在阅读文档时认为正确的方法。在执行任何管理任务之前,我只想从服务器端验证用户(从客户端登录的用户)。问题是在很短的时间内,
$token
不再有效,因此无法发出请求


如何从客户端扩展firebase id令牌会话?

而不是使用
onAuthStateChanged
,后者仅在用户登录或注销时触发,您应该使用,每当刷新用户的身份验证令牌时(每小时自动或在您呼叫时按需)都会触发该会话.

我不明白这里有什么问题。Firebase身份验证登录将永远持续,直到用户注销或其刷新令牌被吊销。ID令牌必须每1小时刷新一次,客户端SDK会自动处理该令牌(无需额外代码)。请编辑此问题,以表明您观察到的与此不同的具体内容。显示代码总是有帮助的。嗨,@DougStevenson。我已经改写了这个问题。请告知。