最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

node.js - How to handle authentication in a backend using Firebase Admin SDK and Express with TypeScript? - Stack Overflow

matteradmin5PV0评论

I am implementing sign-in logic for my app's backend, built using Express with TypeScript, and leveraging the Firebase Admin SDK. However, after exploring the methods provided by the auth instance and browsing the documentation multiple times, I noticed that user authentication seems to primarily occur on the client side via the standard Firebase SDK.

This has left me confused about the best approach:

  • Should I install the regular Firebase SDK in my backend to handle authentication, as I've seen in some articles?
  • Or should the frontend handle authentication entirely while the backend focuses on validating the idToken received from the client using the Firebase Admin SDK?

I'm unsure which option to choose, particularly regarding which approach is more secure and aligns with best practices for authentication.

I am implementing sign-in logic for my app's backend, built using Express with TypeScript, and leveraging the Firebase Admin SDK. However, after exploring the methods provided by the auth instance and browsing the documentation multiple times, I noticed that user authentication seems to primarily occur on the client side via the standard Firebase SDK.

This has left me confused about the best approach:

  • Should I install the regular Firebase SDK in my backend to handle authentication, as I've seen in some articles?
  • Or should the frontend handle authentication entirely while the backend focuses on validating the idToken received from the client using the Firebase Admin SDK?

I'm unsure which option to choose, particularly regarding which approach is more secure and aligns with best practices for authentication.

Share Improve this question edited Nov 18, 2024 at 11:32 jonrsharpe 122k30 gold badges268 silver badges476 bronze badges asked Nov 18, 2024 at 11:29 Simo D.Simo D. 731 silver badge8 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

user authentication seems to primarily occur on the client side via the standard Firebase SDK.

Yes, this is how it works.

Should I install the regular Firebase SDK in my backend to handle authentication, as I've seen in some articles?

No, that won't work well at all. Firebase isn't designed to maintain login state on the backend. The client obtains auth tokens and sends them to the backend when needed.

Or should the frontend handle authentication entirely while the backend focuses on validating the idToken received from the client using the Firebase Admin SDK?

Yes, again, that's how it works. This situation is explained specifically in the documentation:

If your Firebase client app communicates with a custom backend server, you might need to identify the currently signed-in user on that server. To do so securely, after a successful sign-in, send the user's ID token to your server using HTTPS. Then, on the server, verify the integrity and authenticity of the ID token and retrieve the uid from it. You can use the uid transmitted in this way to securely identify the currently signed-in user on your server.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far