jin chong
jin chong

Reputation: 103

firebaseui-web: How to identify user at Node.js backend?

I am building up the typical SPA web site with Node.js backend.

It authenticates the user by Firebaseui-Web.

How can the Node.js(express.js) identify the login user of the request Web API? It seems like it uses token but I cannot find the sample codes.

Many Thanks,

Upvotes: 0

Views: 431

Answers (1)

bojeil
bojeil

Reputation: 30798

With SPA applications, it's not hard. Every time you have an XHR, you call firebase.auth().currentUser.getIdToken() which resolves with the user's ID token and you pass it along with your request either in the header or postBody request. On your backend, you get the ID token if present and verify it using the Firebase Admin SDK node.js library via verifyIdToken. When verified, you get the payload claims identifying the user and return the relevant information for that user. Otherwise you consider the user signed out.

Upvotes: 3

Related Questions