且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Firebase 身份验证服务 - 无需登录即可从电子邮件中查找 uid

更新时间:2023-12-05 10:40:16

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

另见: