Firebase HTTP function accessing userID?

229 views Asked by At

Couple of questions about firebase functions.

I have a function that needs to verify that the current user is authenticated, and then use their userId to store some data and associate it to them.

  • How do i access userId and validate auth in the functions?

  • Where can i get the token that needs to be sent to server through http header?

1

There are 1 answers

2
Doug Stevenson On BEST ANSWER

To get started, look at the official sample code available in GitHub that shows how to protect an endpoint. You'll see that it takes a token from Firebase Authentication for the currently authenticated user using getIdTokenWithCompletion. The function uses the Firebase Admin SDK to verify the token. The result of verification is a DecodedIdToken object, which contains various properties, including the user's uid.