简体   繁体   English

从 Uid 获取用户电子邮件,无需登录应用 Firebase

[英]Get User Email From Uid Without Login to app Firebase

I have created a Firebase app.我创建了一个 Firebase 应用程序。

Is there any way to get user email by Uid Without login to the app?有没有办法在不登录应用程序的情况下通过Uid获取用户电子邮件?

No the user has to be logged in to be able to retrieve his information based on the userid不,用户必须登录才能根据userid检索他的信息

To get the uid, you need to do this:要获取 uid,您需要执行以下操作:

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.如果没有,则返回当前登录的 FirebaseUser 或 null。

more info here:更多信息在这里:

https://firebase.google.com/docs/reference/android/com/google/firebase/auth/FirebaseAuth.html#getCurrentUser() 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 .当然有可能,您可以使用Firebase Cloud Functions You can write a cloud function which will return user mail by UID param :) No firebase authentication required, simple and awesome.您可以编写一个云函数,该函数将通过 UID 参数返回用户邮件 :) 无需 Firebase 身份验证,简单而出色。 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 如果我使用 Firebase 简单用户名和密码身份验证,如何返回用户列表

Use the Firebase Admin SDK.使用 Firebase 管理 SDK。 You can lookup a user by uid, email or phone number: https://firebase.google.com/docs/auth/admin/manage-users#retrieve_user_data您可以通过 uid、电子邮件或电话号码查找用户: 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);
  });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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