通过电子邮件获取uid [英] Get uid by email

查看:311
本文介绍了通过电子邮件获取uid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在网上使用Firebase身份验证,我有一个与此类似的数据库:

I'm using firebase authentication on the web, I have a database similar to this:

categories: {
    c1: {
        name: "Category 1,
    },
    c2: {
        name: "Category 2,
    },
    c3: {
        name: "Category 3,
    }
}
categoryOwners: {
    //u1 and u2 are uids generated by firebase authentication
    u1: { 
        c1: true,
        c3: true
    }
    u2: {
        c1: true,
        c2: true
    }
}

想法是用户可以创建新类别并与其他用户共享.

The idea is that users can create new categories and share them with other users.

因此,用户可以创建一个类别,他将为该类别提供名称,并提供他想共享该类别的人的电子邮件.

So a user could create a category, he'll provide a name for the category and an array of emails from the people he wants to share the category.

是否可以通过前端用户提供的电子邮件从Firebase身份验证中获取uid?

Is there a way to get the uids from firebase authentication by the emails provided by the user in the front end?

我的假设是出于安全原因,我将无法在前端执行此操作,因此我将必须创建一个用户"表并进行维护,否则我可能会创建一个云函数.

My assumption is that I won't be able to do that in the front end for security reasons, so I will have to create a "users" table and maintain it, or maybe I could create a cloud function.

我的假设正确吗?如果是,您认为哪种方法会更优雅?

Is my assumption correct? if it is, what approach do you think would be more elegant?

推荐答案

有一种方法可以通过其电子邮件地址查找用户帐户,但只能在Firebase Admin SDK中.该SDK适用于受信任的环境(即您控制的系统或Cloud Functions).如果您要查找的是此内容,请在检索用户中详细了解数据.

There is a way to look up the user account by its email address, but only in the Firebase Admin SDK. This SDK is meant for use in trusted environments, i.e. a system that you control, or Cloud Functions. If that is what you're looking for, read more about it in retrieving user data.

如果您希望在客户端上运行它,那么确实无法通过用户的电子邮件地址来查找用户的UID.在那种情况下,通常的方法确实是在数据库中创建映射.不过,请务必确保对此数据的访问安全,否则可能会导致用户泄漏所有电子邮件地址的风险.

If you're looking to run this on the client, then indeed there is no way to look up the user's UID by their email address. In that case, the common approach is indeed to create a mapping in the database. Be sure to secure access to this data though, as otherwise you risk leaking all email addresses for your users.

这篇关于通过电子邮件获取uid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆