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

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

问题描述

我正在使用 Firebase、Firebase 的身份验证服务(简单的电子邮件/密码登录)构建一个应用程序,并以与所描述的非常相似的方式存储用户信息 此处.

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.

是否有一种直接的方法可以使用电子邮件来查找 Firebase 定义的 uid(即simpleLogin:9"),而无需遍历所有用户或实际登录他们?

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?

推荐答案

您的 users 节点只是 Firebase 中的一个常规节点.因此,查找项目的唯一方法要么是通过节点的名称,要么是通过节点的优先级.

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.

如果您想坚持使用 uid 作为节点名称,您可以使用 setPrioritysetWithPriority 将电子邮件地址设置为优先级> 然后使用 startAtendAt 过滤.

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);

另见:

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

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