最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论