1

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 Answers1

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.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Thanks for your quick response. I will try integrating this now. –  Jul 20 '18 at 14:25
  • wouldnt that require a request to firebase api everytime to verify token. Isn't it better to authenticate once and store in session? – Jabran Saeed Jul 05 '20 at 08:25
  • The Firebase services actually use the approach I describe, and decode/verify the token on each request. This does not require an additional API call, as they can cache the keys that are needed for this. – Frank van Puffelen Jul 05 '20 at 14:46