Given a email address, is it possbile to get userID of a person? For example,
If I have a variable email that has email of the person. Can I get their ID by doing something like
String userID = mAuth.DatabaseReference.getuID.(email);
Sorry if this a stupid question.
Edit: note, I am looking to get ID of a person who is not the current user. So I can't use FirebaseUser user = mAuth.getCurrentUser();
The structure of my database looks like this, so the ID will be stored in database already. I just need a way of getting it (In the diagram presented below I don't have a field of email but I will be adding one, incase anyone was wondering -_-).
Also, if possible, I would like to get their profile image either based on their email or once I have gotten the id, through ID.
You can't get the name, or any other details of a user that is not currently signed in using FirebaseAuth . Instead, you must create a node in your database where you store the name, and any other necessary details by querying the database.
UIDs in firebase are UUIDs as well. UIDs are nowadays indeed UUIDs.
If you want to look up a user by their email on a trusted server, you can use the Firebase Admin SDK. From the documentation on retrieving user data:
admin.auth().getUserByEmail(email)
.then(function(userRecord) {
// See the tables above for the contents of userRecord
console.log("Successfully fetched user data:", userRecord.toJSON());
})
.catch(function(error) {
console.log("Error fetching user data:", error);
});
The client SDKs for Firebase Authentication only provide access to the profile of the currently authenticated user. They don't provide a way to look up a user by their email address. To allow client-side lookup, the common way to do so is to store the UID-by-email-address in the database:
"emailToUid": {
"SumOne@domain,com": "uidOfSumOne",
"puf@firebaseui,com": "uidOfPuf"
}
With this simple list, you can look up the UID by the encoded email address from:
ref.child("emailToUid").child("SumOne@domain,com").addSingleValueEventListener(...
See also:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With