Firebase Get User UID by Email

前端 未结 1 2025
既然无缘
既然无缘 2020-12-12 04:38

I\'m building an admin panel for my firebase application, and would love to manage users a little easier. I want to be able to look up users by email, and then delete them

相关标签:
1条回答
  • 2020-12-12 04:59

    There is no API in the client SDKs to look up a UID by their email address. Doing this through the database has long been the idiomatic way to do this.

    The operation does however exist in the Firebase Admin SDKs. From the documentation on getting user data:

    admin.auth().getUserByEmail(email)
      .then(function(userRecord) {
        // See the UserRecord reference doc for the contents of userRecord.
        console.log("Successfully fetched user data:", userRecord.toJSON());
      })
      .catch(function(error) {
        console.log("Error fetching user data:", error);
      });
    

    This code is in JavaScript for Node.js, but the Admin SDK also supports this operation in Java, Go, and Python.

    The Firebase Admin SDKs are made to be run in trusted environments, such as a server that you control, or Cloud Functions. They run with administrative privileges, and allow full access to the resources in your project. For this reason, they implement certain operations that are not (securely) possible in the client-side SDKs.

    So if you don't want to list the users from the database, the common approach is to build a backend (can be quite simple) with the Admin SDKs, and call that from your app. Be sure to secure the backend properly, otherwise you'll lose the security benefits that are introduced by having the Admin SDK be separate from the client SDKs.

    0 讨论(0)
提交回复
热议问题