How to get authenticated users from firebase database?

馋奶兔 提交于 2019-12-12 04:37:37

问题


I'm creating app where I will be using Firebase messaging service. Messaging is working fine, but now I wish to make it happen between two users.

I believe I need to provide a authentication for each user then search for their connections(their friends via their social network connections or their mail ids).

I managed to create Google+ authentication in my app using Auth.GOOGLE_SIGN_IN_API and AppInvite.API, but connecting to other users in firebase had no clue, then I went through these links Udacity tutorial and Codelabs tutorial and the Firebase guides. (The tutorials explained the same thing and every one authenticated using the email provider, and not via the Google+ signin. And as a matter fact when I initially tried Google+ signin via these procedures, it didnt work, but email provider is working.)

Anyways email provider is also good for me as of now but still don't have a clue how to connect two users thriugh Firebase. I connected two users, its showing in my Firebase authentication console but how to connect two user one to one?

Any clues??


回答1:


To make a connection between two users in a social network, typically one of them has to enter some "secret" details about the other user. Most common is that you have to enter the email address of your friend and then the system will show you that it has a record matching that email address.

You could implement such a system on Firebase by having a list of email addresses with their corresponding uid:

userLookup
  "ari@stackoverflow,com": "uidOfAri"
  "puf@stackoverflow.com": "uidOfPuf"

Now when I type your email address, I can find your UID (and thus connect with you).

To secure the above, you'd only grant read access on specific users:

{
  "rules": {
    "userLookup": {
      "$user": {
        ".read": true
      }
    }
  }
}

With this structure you can read each specific user, but you cannot search the list of users. So I can only find your uid (and thus connect) if I know your complete email address.



来源:https://stackoverflow.com/questions/40656513/how-to-get-authenticated-users-from-firebase-database

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