Venky
Venky

Reputation: 59

How to delete user by passing UID in firebase?

the config file is :

  import firebase from 'firebase';
  import * as admin from 'firebase-admin';

const config = {
  apiKey: "XX",
  authDomain: "XX",
  databaseURL: "XX",
  projectId: "XX",
  storageBucket: "XX",
  messagingSenderId: "XX",
  appId: "XX"
};
const Admin_config ={

    "type": "service_account",
    "project_id": "XX",
    "private_key_id": "XX",
    "private_key": XX,
    "client_email": "XX",
    "client_id": "XX",
    "auth_uri": "https://accounts.google.com/o/oauth2/auth",
    "token_uri": "https://oauth2.googleapis.com/token",
    "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
    "client_x509_cert_url": "XX"
}
admin.initializeApp({
  credential:admin.credential.cert(Admin_config) ,
  databaseURL: config.databaseURL
});
firebase.initializeApp(config);
export {firebase, admin};

File where I want to delete user, importing the admin and firebase configuration:

import {firebase, admin} from '../config/fbconfig';

 deleteAdmin = (adminDetail) => {
    let uid = ""+adminDetail.UID
    console.log(uid) //I'm getting proper UID here

    admin.auth().deleteUser(uid)
    .then(function() {
      console.log('Successfully deleted user');
    })
    .catch(function(error) {
      console.log('Error deleting user:', error);
    });

  }

The error I'm getting is

Error deleting user: Error: Error while making request: incorrect header check. Error code: Z_DATA_ERROR
    at FirebaseAppError.FirebaseError [as constructor] (error.js:58)
    at FirebaseAppError.PrefixedFirebaseError [as constructor] (error.js:115)
    at new FirebaseAppError (error.js:160)
    at api-request.js:162

I'm unable to delete an user by this way. Please help.

Upvotes: 3

Views: 3386

Answers (1)

shimii
shimii

Reputation: 129

admin
  .auth()
  .deleteUser(uid)
  .then(() => {
    console.log('Successfully deleted user');
  })
  .catch((error) => {
    console.log('Error deleting user:', error);
  });

Refer this for the documentation.

Upvotes: 4

Related Questions