简体   繁体   中英

Get User Email From Uid Without Login to app Firebase

I have created a Firebase app.

Is there any way to get user email by Uid Without login to the app?

No the user has to be logged in to be able to retrieve his information based on the userid

To get the uid, you need to do this:

FirebaseUser user=FirebaseAuth.getInstance().getCurrentUser();
String userid=user.getUid();

According to the docs:

public FirebaseUser getCurrentUser ()

Returns the currently signed-in FirebaseUser or null if there is none.

more info here:

https://firebase.google.com/docs/reference/android/com/google/firebase/auth/FirebaseAuth.html#getCurrentUser()

Of course it is possible, you can use Firebase Cloud Functions . You can write a cloud function which will return user mail by UID param :) No firebase authentication required, simple and awesome. Here is a short example:

const admin = require('firebase-admin');
exports.getUserMail = functions.https.onRequest((req, resp) => {
    admin.auth().getUser(req.query.uid)
}

It is not possible without logging in. Your email address and password are stored separately from the user data for security reasons. See below:

How do I return a list of users if I use the Firebase simple username & password authentication

Use the Firebase Admin SDK. You can lookup a user by uid, email or phone number: https://firebase.google.com/docs/auth/admin/manage-users#retrieve_user_data

admin.auth().getUser(uid)
  .then(function(userRecord) {
    console.log(userRecord.email);
  })
  .catch(function(error) {
    console.log("Error fetching user data:", error);
  });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM