Node.JS Firebase Auth - Is there a way to keep a user session like with client side Firebase Auth?

[亡魂溺海] 提交于 2021-02-11 14:59:52

问题


I am learning Node.JS and I am trying to bring Firebase Auth into my application. With client-side firebase auth, you can just do firebase.auth().currentUser but in node, as the script is not run on the client, but once on the server, you cannot use firebase.auth().currentUser. Is there a way involving sessions or cookies (I think) to get user data and use normal Firebase Auth operations from node just like client side Firebase Auth?

(I am using express with Node)


回答1:


As you've found there is no concept of a current user for a request sent to a node script.

What you'll want to do is use Firebase Authentication on the client, and then send the resulting ID token to your node.js script, where you verify that the token is valid using the Firebase Admin SDK.



来源:https://stackoverflow.com/questions/51444426/node-js-firebase-auth-is-there-a-way-to-keep-a-user-session-like-with-client-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!