Firebase 通过 ID 获取用户 [英] Firebase get user by ID

查看:33
本文介绍了Firebase 通过 ID 获取用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法根据 UID 获取用户信息(如电子邮件、图片)?

Is there a way to get user information (like email, picture) based on its UID?

我的意思不是针对当前登录的用户,而是针对任何其他用户.

I mean not for the currently logged user, but any other user.

推荐答案

如果你使用的是 Firebase 提供的认证方式,那么不行,只能从当前 session/user 中获取,如果需要查询稍后您需要将其保存在您自己的数据存储中.

If you're using the authentication methods provided by Firebase, then no, you can only get it from the current session/user, and if you need to query for it later then you need to save it in your own datastore.

通常我所做的是在身份验证更改时加载用户数据,如果它不存在,那么我保存一个新对象(使用 uid 作为密钥),以及与应用程序相关的任何数据.如果您对图片感兴趣,那么您可能需要经常更新您的数据.

Usually what I do is load the user data when authentication changes, if it's not there then I save a new object (using the uid as key), with whatever data is relevant for the application. If you're interested in the picture then you might need to update your data often.

您可以在以下问题中找到更深入的解释,其中包含一些实际示例:firebase 在哪里保存它的简单登录用户?.

You can find a more in depth explanation, with some actual samples, in the following question: Where does firebase save it's simple login users?.

这篇关于Firebase 通过 ID 获取用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆