如何从 uid 获取 FirebaseUser? [英] How to get FirebaseUser from a uid?
问题描述
假设我有一个用户 ID
Let's say I've a user id
String uid = "1234abcdefgh890";
现在,我想使用这个 uid 获得一个 FirebaseUser
,我该怎么做?
Now, I'd want to get a FirebaseUser
using this uid, how do I do that?
FirebaseAuth auth = FirebaseAuth.instance;
FirebaseUser user = (await auth.signInWithXXX(uid)).user; // is there any method like this
我怎样才能获得 FirebaseUser
呢?
How can I get the FirebaseUser
then?
推荐答案
Firebase 客户端 SDK 中没有 API 来根据 UID 获取用户信息,因为这可能会引起安全问题.
There is no API in the Firebase client-side SDKs to get user information based on a UID, as this could potentially be a security concern.
如果您需要此信息,您可以实现自己的使用 Firebase Admin SDK 的服务器(确实具有此功能),或者您可以将用户信息存储在辅助数据库中,例如Firebase 自己的实时数据库或 Cloud Firestore.然后,您可以从应用程序的其余部分查询此数据库,并使用数据库的服务器端安全规则来保护访问以满足您的需求.
If you need this information, you can either implement your own server that uses the Firebase Admin SDKs (which do have this functionality), or you can store user information in a secondary database, such as Firebase's own Realtime Database or Cloud Firestore. Then you can query this database from the rest of your application, and secure access to fit your needs with the database's server-side security rules.
另见:
- 如果我使用 Firebase 简单用户名,我如何返回用户列表 &密码认证
- Firebase 通过 ID 获取用户
- 如何获取用户Firebase 中基于用户 ID 的电子邮件
- 使用 Firebase 用户 UID 检索配置文件信息
- Firebase 使用 UID 获取身份验证详细信息
这篇关于如何从 uid 获取 FirebaseUser?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!