Guide to removing a user account from Firebase using Angular

I have different users with specific roles. For example, lawyers can delete clients and admins can delete both lawyers and clients. However, as an admin user, I encounter a problem when trying to delete another user. This is because in order to obtain the idToken of another user for deletion, I must first login as that user. Since I am logged in as an admin, I only have my own idToken and not that of the other user. Can someone provide guidance on how to resolve this issue?

Here is what I have tried:

  deleteUser(user: UserModel) {
      this.http.delete(`${this.url}/Users/${user.FirebaseID}.json`).subscribe();
      return this.http.post(`https://identitytoolkit.googleapis.com/v1/accounts:delete?key=${myKey}`,{"idToken":`${user.FirebaseID}`});
    }

However, this approach results in an error stating "idToken Invalid" due to using the Firebase ID instead of the actual idToken. Is there a way to retrieve the idToken without having to login as the targeted user?

Answer №1

The Firebase Admin SDK provides essential tools for managing users with the User Management feature.

An effective approach would be to utilize Cloud Functions for Firebase to execute the Admin SDK. For instance, you could implement it using HTTP triggers.

Alternatively, you can run the Admin SDK on your server. The supported languages are:

  • JavaScript (Node.js)
  • Java
  • Python
  • Go
  • C#

Delete User using Node.js

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

For more details, refer to Manage Users: Delete a user

Also, see: deleteUser

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having difficulty in correctly formatting the material button and implementing underlines exclusively on tab names with Angular

I am struggling to properly display an Angular Material button and I also need to customize the appearance of an Angular tab. Below is a breakdown of my code. routes.component.html:: <div class="content-wrapper"> <div class=" ...

"How to utilize Angular's function to retrieve the difference in object keys

Having trouble comparing two or multiple objects using the difference() function and then extracting the object(s) key value to push into an array of URLs only. I'm facing an issue where I can't use dot syntax on an object, any ideas? Here is th ...

Saving JSON data in a variable or array post subscription: What's the preferred method?

I have been receiving JSON files in the following format: {streetAddress: "Kosterlijand 20", postalCode: "3980", city: "Bunnik", country: "Netherlands"} Although the length of these files varies, the structure always remains the same: {key: "string valu ...

Updating the state in a different component using React and Typescript

The Stackblitz example can be found here I'm attempting to update the useState in one component from another component. Although it seems to work here, it's not functioning properly in my actual application. Here is a snippet of the app.tsx co ...

The error message "./components/Avatar.tsx Error: Module '@babel/preset-stage-0' not found" appeared on the screen

Even after dedicating a few hours to research, I'm still unable to resolve an ongoing issue with Babel and Webpack. ): The solution must be simple. Here is my .babelrc: { "presets": ["@babel/preset-env", "@babel/preset-reac ...

Ways to determine if the keys of an object are present in an array, filtered by the array key

Working on an Angular 2 Ionic application and I'm wondering if there's a straightforward way to filter individuals by age in a specific array and then verify if any key in another object matches the name of a person in the array, returning a bool ...

Autocomplete search from a distance

I am currently learning Angular and trying to create an autocomplete form with content that is filtered on the back-end. I have defined a class and Interface for Terminal: export class Terminal { constructor( public id: number, public name: ...

Circular dependency has been detected when using the ESLint with TypeORM

Having two entity typeorm with a bi-directional one-to-one relationship: Departament: @Entity('Departament') export default class Departament { @PrimaryGeneratedColumn() id: string; @Column() departament_name: string; @OneToOne(type ...

Error Encountered in Angular 2 Unit Test: Custom Pipe Missing - Pipe Not Found

I am encountering an issue with a custom pipe named 'myPipe'. Specifically, I am receiving the following error message: The pipe 'myPipe' could not be found error while running my unit test ts. Can you provide guidance on what needs ...

Checking the formik field with an array of objects through Yup for validation

Here is a snippet of the code I'm working on: https://codesandbox.io/s/busy-bose-4qhoh?file=/src/App.tsx I am currently in the process of creating a form that will accept an array of objects called Criterion, which are of a specific type: export inte ...

What is the syntax for declaring a state variable as a Set data type in programming?

Struggling to establish a state variable in React using Typescript. Encountering an error when attempting to specify its type as Set. The purpose of this variable is to contain an array of objects. const [blocksList, setBlocksList] = useState<Set>([ ...

I am looking to store a collection of objects in Firebase using a single request, and I want Firebase to generate a unique key for each object without using array

I am looking to store a set of objects in Firebase using a single request with a unique key generated by Firebase (without using array indexes as keys). let object_list = { '0': { 'title':'title 1', 'time&apos ...

Struggling with importing aliases in TypeScript for shadcn-ui library

I am facing a challenge with resolving TypeScript path aliases in my project. I have set up the tsconfig.json file to include path aliases using the "baseUrl" and "paths" configurations, but alias imports are not functioning as intended. My goal is to imp ...

Unable to access specific route in Angular if default route contains a parameter

Here is a list of my routes: const routes: Routes = [ { path: '', component: BlogLayoutComponent, children: [ { path: ':pageNumber', component: HomeComponent }, { path: '&apo ...

Creating TypeScript domain objects from JSON data received from a server within an Angular app

I am facing a common challenge in Angular / Typescript / JavaScript. I have created a simple class with fields and methods: class Rectangle { width: number; height: number; area(): number { return this.width * this.height; } } Next, I have a ...

Why is this chip-list not functioning properly in my Angular 14 and Angular material application?

I'm currently developing a form using Angular 14. My goal is to incorporate a field with Angular Material chips. Within the component's Typescript file, I have the following code: constructor(private fb: FormBuilder,) { } public visible: boole ...

Error TS2307: Module 'calculator' could not be located

Running a Sharepoint Framework project in Visual Studio Code: This is the project structure: https://i.stack.imgur.com/GAlsX.png The files are organized as follows: ComplexCalculator.ts export class ComplexCalculator { public sqr(v1: number): number ...

Send the NameSpace to the object and store it in the local storage

Hey there! I've developed an Android application that accesses the device certificates to retrieve specific information (APPCID). handleCertificate(appId) { OData.defaultHttpClient = sap.AuthProxy.generateODataHttpClient(); this.factory.connectionDa ...

When trying to import the "firebase/app" module, an error occurred stating that the default condition should be the last one to be considered

Greetings! I am diving into the world of webpack and firebase. Every time I use: import { initializeApp } from "firebase/app"; I encounter this error message: https://i.sstatic.net/tvuxZ.png Here is my file structure: https://i.sstatic.net/406o ...

How can I resolve the problem of transferring retrieved data to a POST form?

When it comes to the form, its purpose is to send data fetched from another API along with an additional note. The fetched data was successfully received, as I confirmed by logging it to the console. It seems that the form is able to send both the fetche ...