Firebase Authentication Service - lookup uid from email without login

谁说我不能喝 提交于 2019-11-27 19:32:04

问题


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?


回答1:


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:

  • Database-style Queries with Firebase
  • How to query firebase for property with specific value inside all children
  • Top results from Googling "Firebase where query".


来源:https://stackoverflow.com/questions/26019279/firebase-authentication-service-lookup-uid-from-email-without-login

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