1

I am trying to set up some admin functionality which allows admin users to delete another user's authentication from the client. How can I do this?

From reading the docs, it seems it is not possible for a user to directly delete another user, and I will have to use something like the Admin SDK with cloud functions and maybe Firestore? I already have a users node in Firestore which contains their email and whether they are admin or a regular user.

Max888
  • 3,089
  • 24
  • 55

1 Answers1

1

You have to use Admin SDK to delete a user, right. But I don't think it can be done on client side.

Firebase-Admin, importing it to react application throws Module not found error

Below is backend approach:

You need the env variables:

GOOGLE_APPLICATION_CREDENTIALS=xxx
FIRESTORE_DB_URL=xxx

GOOGLE_APPLICATION_CREDENTIALS - this is path to your service account key file.

import * as admin from 'firebase-admin';

admin.initializeApp({
    credential: admin.credential.applicationDefault(),
    databaseURL: process.env.FIRESTORE_DB_URL
});

The SDK automatically find your credentials file from the GOOGLE_APPLICATION_CREDENTIALS.

And you can remove a user with his uid:

admin.auth().deleteUser(UID);

There is another way to initialize the admin sdk by using refresh token. https://firebase.google.com/docs/admin/setup

critrange
  • 5,652
  • 2
  • 16
  • 47