首页 > 解决方案 > How to delete user account from firebase with angular

问题描述

I have some users and this user has roles , lawyers can delete clients and admins can delete lawyers and clients , but when i am logged in as admin i can delete another user because i can get idToken of another user because to get the idToken i need to login with this user and i am logged in with my admin user and i only have my idToken no the token of the another user. can anyone help me ?

i try this :

  borrarUsario(usuario:UsuarioModel)
    {


      this.http.delete(`${this.url}/Usuarios/${usuario.FireBaseID}.json`).subscribe();
      return this.http.post(`https://identitytoolkit.googleapis.com/v1/accounts:delete?key=${myKey}`,{"idToken":`${usuaro.FireBaseID}`});


    }

but this response with error idToken Invalid because the idToken is not the Firebase ID , how can i get the idToken witouth login with the another user

标签: angulartypescriptfirebasefirebase-realtime-databasefirebase-authentication

解决方案


Firebase Admin SDK提供了用户管理所需的工具。

一种选择是利用Cloud Functions for Firebase来运行 Admin SDK,例如,使用HTTP tiggers

或者在您的服务器上使用 Admin SDK。开箱即用支持以下语言:

  • JavaScript (Node.js)
  • 爪哇
  • Python
  • C#

使用 Node.js 删除用户

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

请参阅管理用户:删除用户

看:deleteUser


推荐阅读