简体   繁体   English

Firebase 在 ReactJS 应用程序中使用 JWT 令牌进行身份验证

[英]Firebase Authentication Using JWT token in ReactJS App

I currently have a frontend (ReactJS) and backend (Django) completely running.我目前有一个完全运行的前端(ReactJS)和后端(Django)。 I am now looking into real-time updates for certain parts of my application and I have decided to go with Firebase because it allows me to deploy quickly and scale easily later on.我现在正在研究应用程序某些部分的实时更新,我决定将 go 与 Firebase 一起使用,因为它允许我以后快速部署并轻松扩展。

However, as I already have an entire backend setup, which authenticates the user and sends back a token (JWT), I would like to know how I can use the same authentication for Firebase.但是,由于我已经有一个完整的后端设置,它对用户进行身份验证并发送回一个令牌 (JWT),我想知道如何对 Firebase 使用相同的身份验证。 The idea would be to set custom rules in Firebase based on the userID, and to use this userID (which is just a regular id, eg my userID is 1, not a UUID) to create collections inside the real-time database and Firestore.想法是根据用户 ID 在 Firebase 中设置自定义规则,并使用此用户 ID(这只是一个常规 ID,例如我的用户 ID 是 1,而不是 UUID)在实时数据库和 Firestore 中创建 collections。

I have already read the docs on custom tokens, but I haven't understood it properly.我已经阅读了关于自定义令牌的文档,但我没有正确理解它。

Can I use this to sign a user in, without using Firebase Auth?我可以使用它来登录用户,而不使用 Firebase Auth 吗? Or will this create a user in Firebase Auth too?或者这也会在 Firebase Auth 中创建一个用户?

You can implement a Firebase Auth custom authentication provider if you want to use your own user auth system with Firebase Auth, in order to use security rules.如果您想将自己的用户身份验证系统与 Firebase 身份验证一起使用,您可以实施Firebase 身份验证自定义身份验证提供程序,以便使用安全规则。 Your users will have to be signed in with Firebase Auth client SDK in order for this to work correctly, and your backend will need to produce a JWT .您的用户必须使用 Firebase Auth 客户端 SDK 登录才能正常工作,并且您的后端将需要生成 JWT The linked documentation should have everything you need to get started.链接的文档应该包含您入门所需的一切。 If you are confused about something, please ask a new question that describes in detail where you are stuck with your implementation.如果您对某事感到困惑,请提出一个新问题,详细描述您在实施中遇到的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM