Get uid by email

2020-05-01 06:24发布

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.

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?

1条回答
Emotional °昔
2楼-- · 2020-05-01 06:43

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.

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.

查看更多
登录 后发表回答