【发布时间】:2020-12-18 08:43:37
【问题描述】:
我正在使用 Firebase 身份验证,我需要将经过身份验证的用户存储在我自己的用户表中(我只打算使用 firebase 身份验证,而不是他们的后端服务)。但是,我不确定应该使用 firebase 提供的哪个值作为唯一标识符。
在文档中,Firebase 指出:
uid = user.uid; // The user's ID, unique to the Firebase project. Do NOT use
// this value to authenticate with your backend server, if
// you have one. Use User.getToken() instead.
根据上面的评论(见此处:https://firebase.google.com/docs/auth/web/manage-users),这意味着我不能依赖uid?
他们是说我应该使用
user.getIdToken().then((token) => {
// is this my UUID that I should store in my own db
// this one? Its 926 characters long,
console.log(token);
});
【问题讨论】:
-
值得一提的是,尽管您可能不想使用其他一些 Firebase 产品,但您可能会发现在 Google Cloud Platform 范围内托管您的服务以帮助减少身份验证时的网络延迟会更高效到您的后端。 IMO Cloud Run 对于 API 来说是特别好的产品,并且与 Firebase Auth 配合得非常好。
-
ELI5?不知道
more performant to host your service within the realm of the Google Cloud Platform to help reduce network latency是什么意思@什么服务? -
我假设您有一个您对其进行身份验证的前端应用程序。由于您选择不使用 Firebase 函数或直接从客户端应用调用 Firestore,您需要通过其他方式提供一些后端功能,通常使用 API 服务?
-
是的。我计划在后端使用 Django(作为我的 nuxt 前端的 rest api)和 Postgres db。我转向 firebase 的唯一原因是因为 SPA 上的身份验证很难设置 IMO
-
我使用 JavaScript 编写了答案,因为这是问题中唯一可用的标签。您需要调整以下示例以在服务器端代码 firebase.google.com/docs/reference/admin/python/… 上使用 Python 等效项
标签: javascript firebase-authentication