1

Let's say I've a user id

String uid = "1234abcdefgh890";

Now, I'd want to get a FirebaseUser using this uid, how do I do that?

FirebaseAuth auth = FirebaseAuth.instance;
FirebaseUser user = (await auth.signInWithXXX(uid)).user; // is there any method like this 

How can I get the FirebaseUser then?

iDecode
  • 22,623
  • 19
  • 99
  • 186
  • Is this helpfull? https://stackoverflow.com/questions/29889729/how-to-get-the-user-email-in-firebase-based-on-user-id/49002292 – marsh-wiggle Feb 26 '20 at 12:23
  • Thanks but it wasn't quite useful. – iDecode Feb 26 '20 at 12:32
  • 2
    Not sure if you can get a FirebaseUser, But a little hack you can use, is to Create a User model (class) with a factory function that takes a DocumentSnapshot and returns a User instance. So all you have to do is query a document with a given id. and with the returend DocumentSnapshot you can create a User. – Abdelbaki Boukerche Feb 26 '20 at 15:09

1 Answers1

3

There is no API in the Firebase client-side SDKs to get user information based on a UID, as this could potentially be a security concern.

If you need this information, you can either implement your own server that uses the Firebase Admin SDKs (which do have this functionality), or you can store user information in a secondary database, such as Firebase's own Realtime Database or Cloud Firestore. Then you can query this database from the rest of your application, and secure access to fit your needs with the database's server-side security rules.

Also see:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807