问题
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