Firebase Authentication Service - lookup uid from email without login

时光总嘲笑我的痴心妄想 提交于 2019-11-28 14:12:05
Frank van Puffelen

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:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!