如何删除 Firebase 身份验证中的所有用户?

How to delete all users in Firebase auth?

我正在尝试删除我在 Firebase 身份验证中存储的所有用户。

不确定为什么 Firebas 控制台中没有我可以单击或 select 多个用户可以同时单击的“按钮”。无论如何...

我试过像这样设置一个可调用的云函数:

export const deleteUsers = functions.https.onCall(
    async (req: any, res:any): Promise<any> => {
      const allUsers = await admin.listUsers();
      const allUsersUID = allUsers.users.map((user: { uid: any; }) => user.uid);
      return admin.deleteUsers(allUsersUID).then(() => res.send("deleted"));
    }
  );

但是,当我尝试使用 deleteUsers()firebase:shell 调用它时,出现以下 400 错误:

firebase > deleteUsers()
Sent request to function.
firebase > >  {"severity":"WARNING","message":"Request body is missing data."}
>  {"severity":"ERROR","message":"Invalid request, unable to process."}

RESPONSE RECEIVED FROM FUNCTION: 400, {
  "error": {
    "message": "Bad Request",
    "status": "INVALID_ARGUMENT"
  }
}

如果我改为使用 deleteUsers({}) 调用它,我会收到以下 500 错误:

firebase > deleteUsers({})
Sent request to function.
firebase > >  {"verifications":{"app":"MISSING","auth":"MISSING"},"logging.googleapis.com/labels":{"firebase-log-type":"callable-request-verification"},"severity":"INFO","message":"Callable request verification passed"}
>  {"severity":"ERROR","message":"Unhandled error TypeError: res.on is not a function\n    at C:\Users\jastr\Documents\Company\chess-marketplace\node_modules\firebase-functions\lib\common\providers\https.js:365:17\n    at new Promise (<anonymous>)\n    at C:\Users\jastr\Documents\Company\chess-marketplace\node_modules\firebase-functions\lib\common\providers\https.js:364:16\n    at newHandler (C:\Users\jastr\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:315:16)\n    at fixedLen (C:\Users\jastr\Documents\Company\chess-marketplace\node_modules\firebase-functions\lib\providers\https.js:120:41)\n    at C:\Users\jastr\Documents\Company\chess-marketplace\node_modules\firebase-functions\lib\common\providers\https.js:400:32\n    at processTicksAndRejections (node:internal/process/task_queues:96:5)\n    at async runFunction (C:\Users\jastr\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:547:9)\n    at async runHTTPS (C:\Users\jastr\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:573:5)\n    at async handler (C:\Users\jastr\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:493:17)"}

RESPONSE RECEIVED FROM FUNCTION: 500, {
  "error": {
    "message": "INTERNAL",
    "status": "INTERNAL"
  }
}

我做错了什么?

调用 callable Cloud Function 要求您遵循实现该协议的 protocol or use an SDK

如果您只想在 Node 脚本中执行代码,您可以将其声明为:

export const deleteUsers = function() { 
  ...
}