Firebase身份验证服务 - 通过电子邮件查找uid,无需登录 [英] Firebase Authentication Service - lookup uid from email without login

查看:182
本文介绍了Firebase身份验证服务 - 通过电子邮件查找uid,无需登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Firebase,Firebase的身份验证服务(简单的电子邮件/密码登录)构建应用程序,并以与 here

我的部分功能需要允许根据电子邮件地址查找另一个用户。

是否有直接的方式使用电子邮件查找Firebase定义的uid(即simpleLogin:9),而无需遍历所有用户,或者能够实际登录他们?

解决方案您的用户节点只是一个常规Firebase中的节点。因此,查找项目的唯一方法是通过节点的名称或节点的优先级。

如果您想坚持使用 uid 作为节点名称,您可以将电子邮件地址设置为优先使用 setPriority setWithPriority ,然后使用 startAt endAt

  //将新用户的个人资料保存到Firebase中, 
//列出用户,在安全规则中使用它们,并显示配置文件
myRef.child('users')。child(user.uid).setWithPriority({
displayName:user.displayName ,
provider:user.provider,
provider_id:user.id
,user.email);
$ b $ var userRef = myRef.child('users')。startAt(user.email).endAt(user.email);但是,如果你只使用简单的电子邮件,你可能会考虑简单地存储用户的电子邮件地址开始:

$ p $ myRef.child('users')。child(user.email).set({
displayName:user.displayName,
provider:user.provider,
provider_id:user.id
});
$ b $ var userRef = myRef.child('users')。child(user.email);

另见:

$ ul

  • 使用Firebase进行数据库式查询

  • 如何查询firebase for
  • Google搜索结果最佳搜索结果Firebase where query。


  • I am building an app using Firebase, Firebase's Authentication Service (simple email/password login), and storing user information in a manner pretty similar to what is described here.

    Part of my functionality will need to allow looking up another user based on an email address.

    Is there a straightforward way to use an email to lookup the Firebase defined uid (i.e. 'simpleLogin:9') without having to iterate over all users, or being able to actually log them in?

    解决方案

    Your users node is just a regular node in Firebase. So the only way to look up items is either by the name of the node or by the priority of the node.

    If you want to stick to using the uid as the node name, you can set the email address as the priority using setPriority or setWithPriority and then filter using startAt and endAt.

      // save new user's profile into Firebase so we can
      // list users, use them in security rules, and show profiles
      myRef.child('users').child(user.uid).setWithPriority({
        displayName: user.displayName,
        provider: user.provider,
        provider_id: user.id
      }, user.email);
    
      var userRef = myRef.child('users').startAt(user.email).endAt(user.email);
    

    But if you're only using simple email, you might consider simply storing the users by their email address to begin with:

      myRef.child('users').child(user.email).set({
        displayName: user.displayName,
        provider: user.provider,
        provider_id: user.id
      });
    
      var userRef = myRef.child('users').child(user.email);
    

    See also:

    这篇关于Firebase身份验证服务 - 通过电子邮件查找uid,无需登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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