Firebase Firestore 使用现有的用户数据后端集成聊天

Firebase Firestore integrate chat using existing backend for user data

我开发了一个 iOS 应用程序,我正在使用 Node 和 Postgres 来处理用户数据和身份验证。我想在我的应用程序中添加聊天功能,为此我选择了 Firestore。

我的问题是我应该如何 link 现有用户数据与 Firebase 用户集合而不从头开始重新实现身份验证部分。现在,身份验证基于具有访问和刷新令牌的 JWT。

为了 link 我的现有用户,我可以将我的数据库中已经存在的 userId 添加到我将在 Firestore 中创建的 users 集合,但我需要一些一种确保安全的身份验证。

虽然 Firebase 的令牌也是一个 JWT,但它可能必须与您现有的 JWT 分开,因为它包含特定于 Firebase 的信息(例如项目 ID),并且它们使用不同的密钥进行签名.

在您使用自己的后端对用户进行身份验证后,mint a custom token for Firebase authentication with the information you want to use in Firebase/Firestore and security rules, pass that to the client, and sign them in 使用它到 Firebase。