简体   繁体   English

从 flutter 中的电话号码获取用户 ID

[英]getting user id from phone number in flutter

in the app, which logs the user in only through phone authentication.在应用程序中,该应用程序仅通过电话身份验证登录用户。 now the question is can I get the user id from his phone number(not the user id of the current user though).现在的问题是我可以从他的电话号码中获取用户 ID(虽然不是当前用户的用户 ID)。 I have the access to other users phone number in the app, and I want to get their id for further use.我可以访问应用程序中的其他用户电话号码,并且我想获取他们的 ID 以供进一步使用。 is it possible in flutter with firebase at the backend?是否可以在 flutter 与 firebase 在后端?

Looking up the UID for a user based on either phone number or email address is considered a sensitive operation.根据电话号码或 email 地址查找用户的 UID 被视为敏感操作。 For this reason such operations are only available in the Admin SDKs, which are designed to be used in trusted environments, such as your development machine, a server you control, or Cloud Functions.出于这个原因,此类操作仅在 Admin SDK 中可用,这些 SDK 旨在用于受信任的环境,例如您的开发机器、您控制的服务器或 Cloud Functions。 For more on these, see the bottom two code samples in looking up user data in the documentation.有关这些的更多信息,请参阅文档中查找用户数据的底部两个代码示例。

If you want to perform such operations from your client-side code, your two main options are:如果您想从客户端代码执行此类操作,您的两个主要选项是:

  1. Store the required mapping in a cloud-hosted database, such Firebase's Realtime Database or Firestore, as Huthaifa also answered .将所需的映射存储在云托管数据库中,例如 Firebase 的实时数据库或 Firestore,正如Huthaifa 也回答的那样。

  2. Create your own custom API on a server or Cloud Functions where you lookup the user through the Admin SDK.在您通过管理员 SDK 查找用户的服务器或 Cloud Functions 上创建您自己的自定义 API。 Your client-side application code can then call this custom API.然后,您的客户端应用程序代码可以调用此自定义 API。

In both of these cases you are in full control of what data you share, and how you secure access.在这两种情况下,您都可以完全控制您共享的数据以及如何保护访问。

Sure you can, there are multiple approaches for this, if you post your structure for the user model, or how you are storing them in firebase.当然可以,有多种方法可以解决此问题,如果您为用户 model 发布您的结构,或者您如何将它们存储在 firebase 中。

You can run a simple Firebase query like this example: FirebaseFirestore.instance.collection('users').where('phoneNumber', isEqualTo: thePhonenumberOftheuserYouwant2GetUIDfor).get()您可以运行一个简单的 Firebase 查询,如下例所示: FirebaseFirestore.instance.collection('users').where('phoneNumber', isEqualTo: thePhonenumberOftheuserYouwant2GetUIDfor).get()

You can also store the available\accessible contacts for every user in their user document, and when your user logs in, it'll fetch all their allowed user numbers.您还可以将每个用户的可用\可访问联系人存储在他们的用户文档中,当您的用户登录时,它将获取他们所有允许的用户号码。

The more information you provide to your problem, the more StackOverflow can provide you back.您为问题提供的信息越多,StackOverflow 可以为您提供的回馈就越多。

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

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