Is it possible to get the firebase user via UID?

Asked

Viewed 1,849 times

2

Doubt consists in the following problem:

I have a project using firebase and Ionic 3. I am using the authentication mode via E-mail, in which you have the email and UID stored.

For example: I have 2 users registered at the base.

[email protected] UID = 123

[email protected] UID = 321

In my code I have a message element that has the id of who is sending, for example:

Message 1 = Description: "Description", idUsuario: "123"

I am logged in with the UID 321 user and want to recover the UID 123 user to display his email, how do I do this?

I did not want to store in the firebase database, but since there is no other way, then, someone would know how to create a registration screen that registers via email/ password and stores in firebase this data.

PS: I am trying to use authentication via logged-in user token to write to the database, but to do the registration there is no token, so I am not getting.

This way:

 return this.http
  .post(this.urlDataBase + email + '/user.json?auth=' + token, usuario)
  .map((response: Response) => {
    console.log(response);
    return response.json();
  });

But it is not saving in firebase, it is giving error 400:

Response {_body: "{↵  "error" : "Invalid path: Invalid token in path"↵}↵", status: 400, ok: false, statusText: "Bad Request", headers: Headers, …}
  • 1

    according to this reply is not possible: https://stackoverflow.com/questions/14673708/how-do-i-return-a-list-of-users-if-i-use-the-firebase-simpleusername-password

  • 1

    Only using Authentication is not possible. You will need to use the database

  • 1

    Thank you. Sacanagem not have a way to access this data...

  • 2

    The data of your message is stored in the Real Time Data Base of firebase?? when you saved can not put the email soon not?

2 answers

3


As stated in Link, it is not possible to do this reading of Firebase directly, but there are some other ways to do the validations so that CRUD operations can be performed directly in firebase.

When using email / password Authentication in Firebase Authentication (Previously known as Firebase Simplelogin), your user’s email and password Combination is securely stored separately from the data Actually stored in your Firebase.

This Barrier between the data in your Firebase and your users' email / password hash Combinations is by design: we want to make it easier for you to (1) develop your application, (2) Prevent any Accidental user Credential Leaks, and (3) still Give you total flexibility with how to store your user data in Firebase.

*That Means that we only store the email address / password hash Combination and Nothing Else, so it is up to you to decide how to store actual user data in your Firebase. *

GOOGLE TRANSLATE - TRANSLATION

When using email authentication / password in Firebase Authentication (formerly known as Firebase Simplelogin), the user’s email combination and password is securely stored separately from the data stored in Firebase.

This barrier between the data in your Firebase and the users' password/email hash combinations is by design: we want to make it easy for you (1) to develop your application, (2) prevent any accidental leakage of user credentials and (3) still offers total flexibility on how to store your user data in Firebase.

This means that we only store the email address/password hash combination and nothing else. So it’s up to you to decide how to store real user data in your Firebase.


Well you can take the user ID and store this data in your Firebase in a location like /users/$id and use the Firebase Security Rules Language to determine read/write access to that data. Your users' unique email and ID are already in the auth variable that you will use when writing the rules.

Another alternative is

  • The application sign in with an "Admin" access (Read and/or write only [depends on needs])
  • Grab a list of Firebase users
  • Use list to make necessary validations

This way you would be logged in and will be able to do the operations of user creation, data update, delete a user, read users etc.

1

I went through the same problem. There is no other way than to store this user’s UID + information inside the Firestore/Real Database.

Firestore Authentication is actually an isolated user authentication service, as is Cognito from AWS where access information is stored within that service.

Searching a little, I realized that I should store within a collection "User" the user data (name, surname, email, city...) and also the UID as key (id).

The flow was basically :

1) The user registers in the application 2) Firestore Authentication generates a new authenticated 3) I automatically create a new DOC within the "User" Collection having the ID identical to the UID generated within the FA.

Within the official Firestore forum I found many people saying that this would not be "incorrect", because the user’s UID does not offer any possibility of access to sensitive data and is also not a.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.