Christopher Mills
Christopher Mills

Reputation: 760

Fetching another user's data based on their uid

I'm trying to impliment the following form the docs:

UserRecord userRecord = FirebaseAuth.getInstance().getUser(uid);

However, it doesn't seem to be recognised, nor is there an option to import anything to be able to use it.

I have the following in my build file:

    implementation 'com.google.firebase:firebase-core:16.0.0'
    implementation 'com.google.firebase:firebase-auth:16.0.1'
    implementation 'com.google.firebase:firebase-database:16.0.1'
    implementation 'com.google.firebase:firebase-storage:16.0.1'
    implementation 'com.firebaseui:firebase-ui-database:3.2.2'

Upvotes: 0

Views: 89

Answers (2)

Frank van Puffelen
Frank van Puffelen

Reputation: 598728

The code in your question is from the Firebase Admin SDK, which is an SDK meant for use in environments you control (e.g. a server or your development laptop).

The build.gradle fragments you shared are for an Android app. The Firebase Admin SDK is not compatible with Android apps.

There is no way to get the user profile for another user in the Android SDK. If there was, anyone could reverse engineer your Android app, and look up information for any of your users.

What you could do is use the Admin SDK to expose an endpoint that your Android app can call. But you'd need your own way of setting up a Java endpoint for that, or alternatively use the Admin SDK for Node.js and serve it from Cloud Functions. In either of those cases, be aware that an unprotected endpoint allowing such a lookup will probably be seen as a breach of trust by you users.

Upvotes: 1

Raja Osama
Raja Osama

Reputation: 143

Well you cant just get all user data unless you know what you are doing .

STEP one create a JSON ARRAY of name users that contain all the ids of the users that you add in .

STEP two call users in datasnapshot get all of their ids and if you want you can save the users data within those uid in real time database .

YOU CANNOT GET ALL THE USERS INFO JUST FROM YOUR USERS AND NO REFRENCE IN REAL TIME DB

Upvotes: 0

Related Questions