简体   繁体   English

使用Node.js后端持久登录Firebase

[英]Persist Firebase login with Node.js backend

When I've looked up how to check if the user requesting a certain view is logged in, many people suggest using firebase.auth().currentUser , but when I read the docs, it says that firebase.auth().currentUser just shows you if any user is logged in which doesn't really help me when I'm getting a request to my Node server, and I want to see if the user is logged in. 当我查找如何检查请求某个视图的用户是否已登录时,许多人建议使用firebase.auth().currentUser ,但是当我阅读文档时,它说firebase.auth().currentUser只是向您显示是否有任何用户登录,当我收到对Node服务器的请求时,并没有真正帮助我,我想查看该用户是否已登录。

So what is the idiomatic way to let a user login in Firebase, keep them logged in, and have a function to tell you if they're logged in? 那么,让用户登录Firebase,使其保持登录状态并具有告诉用户是否已登录的功能的惯用方式是什么?

Assuming that the user is authenticating to Firebase on the client side, the typical approach is for the client to pass an ID token to the server to identify the Firebase user for the session. 假设用户正在客户端上对Firebase进行身份验证,则典型方法是让客户端将ID令牌传递给服务器,以标识会话的Firebase用户。 See this documentation for details on how to generate the ID token on the client and then verify it on the server. 有关如何在客户端上生成ID令牌,然后在服务器上进行验证的详细信息,请参阅此文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM