Tako
Tako

Reputation: 672

Connect user to Firebase from front and back

Here is my case :

So my question is how can I handle front and back user authentication with Firebase ?

How can I get the Firebase auth cookie then send it to my webservice to auth my user ?

Upvotes: 0

Views: 322

Answers (1)

Pat Needham
Pat Needham

Reputation: 5638

Firebase provides some documentation on how to verify ID tokens. To retrieve the ID token within your client-side Angular code, you can do this:

firebase.auth().currentUser.getToken(/* forceRefresh */ true).then(function(idToken) {
  // Send token to your backend via HTTPS
  // ...
}).catch(function(error) {
  // Handle error
});

And to verify the idToken on the server:

// idToken comes from the client app (shown above)
admin.auth().verifyIdToken(idToken)
  .then(function(decodedToken) {
    var uid = decodedToken.uid;
    // ...
  }).catch(function(error) {
    // Handle error
  });

Upvotes: 1

Related Questions