[英]Delete all users from firebase auth console
Is there an easy way to delete all registered users from firebase console?有没有一种简单的方法可以从 firebase 控制台中删除所有注册用户? For example, I created a hundred users from my development environment, and now I want to delete all of them.
例如,我从我的开发环境中创建了一百个用户,现在我想删除所有这些用户。
As in updated answer, you can probably use firebase admin tools now, but if you don't want – here is a bit more solid javascript to remove users in the web:正如在更新的答案中一样,您现在可能可以使用 firebase 管理工具,但如果您不想 - 这里有一些更可靠的 javascript 来删除网络中的用户:
var intervalId;
var clearFunction = function() {
var size = $('[aria-label="Delete account"]').size()
if (size == 0) {
console.log("interval cleared")
clearInterval(intervalId)
return
}
var index = Math.floor(Math.random() * size)
$('[aria-label="Delete account"]')[index].click();
setTimeout(function () {
$(".md-raised:contains(Delete)").click()
}, 1000);
};
intervalId = setInterval(clearFunction, 300)
Just run it in developer tools只需在开发人员工具中运行
Try this code for the latest Firebase update.试试这个代码以获得最新的 Firebase 更新。 Open the console, paste this code and hit enter!!!
打开控制台,粘贴这段代码并回车!!!
setInterval(() => {
document.getElementsByClassName('edit-account-button mat-focus-indicator mat-menu-trigger mat-icon-button mat-button-base')[0].click()
let deleteButtonPosition = document.getElementsByClassName('mat-focus-indicator mat-menu-item ng-star-inserted').length - 1
document.getElementsByClassName('mat-focus-indicator mat-menu-item ng-star-inserted')[deleteButtonPosition].click()
document.getElementsByClassName('confirm-button mat-focus-indicator mat-raised-button mat-button-base mat-warn')[0].click()
}, 1000)
Because I'm pretty lazy at clicking buttons and elements in the UI, I set up a small client script:因为我很懒惰点击 UI 中的按钮和元素,所以我设置了一个小的客户端脚本:
$('[aria-label="Delete account"]').click()
setTimeout(function () {
$(".md-raised:contains(Delete)").click()
}, 1000);
You may need to run it multiple times, but it is much better than wasting the time clicking things on the screen manually.您可能需要多次运行它,但这比浪费时间手动单击屏幕上的东西要好得多。
setInterval(() => {
$('[aria-label="Delete account"]').first().click()
setTimeout(()=>{
$(".md-raised:contains(Delete)").click()
}, 100)
}, 2000);
designed to avoid calling delete
endpoint very often, since google fails with 404
error.旨在避免经常调用
delete
端点,因为 google 失败并出现404
错误。
Using the Firebase Admin SDK is really easy and the recommended way to perform such tasks on your Firebase data.使用 Firebase Admin SDK非常简单,并且是对 Firebase 数据执行此类任务的推荐方法。 This solution is unlike the other makeshift solutions using the developer console.
该解决方案不同于使用开发者控制台的其他临时解决方案。
I just put together a Node.js script to delete all users in your Firebase authentication.我只是整理了一个 Node.js 脚本来删除您的 Firebase 身份验证中的所有用户。 I have already tested it by deleting ~10000 users.
我已经通过删除约 10000 个用户对其进行了测试。 I simply ran the following Node.js code.
我只是运行了以下 Node.js 代码。
Create a new folder.新建一个文件夹。 Run the following in terminal
在终端中运行以下命令
npm init
sudo npm install firebase-admin --save
Now create an index.js
file in this folder.现在在这个文件夹中创建一个
index.js
文件。
Generate new Private Key
to download the JSON file.Generate new Private Key
以下载 JSON 文件。 Copy the path to JSON file and replace it in the code below in the path to service accounts private key json file.databaseURL
from the settings page.databaseURL
。 Replace it in the code.index.js
.index.js
中。node index.js
.node index.js
中运行。 Watch the mayhem!var admin = require('firebase-admin');
var serviceAccount = require("/path/to/service/accounts/private/key/json/file");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "/url/to/your/database"
});
function deleteUser(uid) {
admin.auth().deleteUser(uid)
.then(function() {
console.log('Successfully deleted user', uid);
})
.catch(function(error) {
console.log('Error deleting user:', error);
});
}
function getAllUsers(nextPageToken) {
admin.auth().listUsers(100, nextPageToken)
.then(function(listUsersResult) {
listUsersResult.users.forEach(function(userRecord) {
uid = userRecord.toJSON().uid;
deleteUser(uid);
});
if (listUsersResult.pageToken) {
getAllUsers(listUsersResult.pageToken);
}
})
.catch(function(error) {
console.log('Error listing users:', error);
});
}
getAllUsers();
firebaser here火力基地在这里
We just released the Firebase Admin SDK , which supports administrative use-cases, such as deleting a user account without requiring that user to sign in first .我们刚刚发布了Firebase Admin SDK ,它支持管理用例,例如无需用户先登录即可删除用户帐户。
original answer原始答案
There is currently no API in Firebase Authentication to delete a user without requiring that user to sign in. We know this limits the usability of our API and are working to add such functionality in a future release. Firebase 身份验证中目前没有 API 可以在不要求用户登录的情况下删除用户。我们知道这会限制我们 API 的可用性,并正在努力在未来的版本中添加此类功能。 But as usual, we don't provide specific timelines for when the feature will be available.
但像往常一样,我们没有提供该功能何时可用的具体时间表。
For the moment your only work arounds are to:目前,您唯一的解决方法是:
Slightly increased your helper script.稍微增加了你的帮助脚本。
German firebase site version:德国 firebase 网站版本:
$('[aria-label="Nutzermenü öffnen"]').click();
$('[aria-label="Konto löschen"]').click();
for (i = 0; i < 20; i++) {
setTimeout(() => {
$('.md-raised:contains(Löschen)').click();
}, i * 200);
}
For the english version just replace the text.对于英文版,只需替换文本。 This way you can delete 20 or more users once executed.
这样,您可以在执行后删除 20 个或更多用户。
Used this code successfully on 11/16/2020: 2020 年 11 月 16 日成功使用此代码:
setInterval(function () {
$('[aria-label="View more options"]')[0].click()
document.querySelectorAll('.mat-menu-item')[2].click()
document.querySelector('.confirm-button').click()
}, 1000);
setInterval(() => {
if ($('[aria-label="Delete account"]').length > 0) {
$('[aria-label="Delete account"]').first().click()
setTimeout(()=>{
$(".md-raised:contains(Delete)").click()
}, 100)
} else {
$('[aria-label="Reload"]').first().click()
}
}, 2000);
Try this one.试试这个。 It's an update to @www.eugenehp.tk answer above that takes into account the need to refresh the page if you have more than one page of entries.
这是对上面@www.eugenehp.tk 答案的更新,考虑到如果您有超过一页的条目,则需要刷新页面。
setInterval(() => { document.getElementsByClassName('edit-account-button mat-focus-indicator mat-menu-trigger mat-icon-button mat-button-base')[0].click() var buttons = document.getElementsByClassName('mat-focus-indicator mat-menu-item ng-star-inserted'); buttons.item(buttons.length - 1).click(); document.getElementsByClassName('confirm-button mat-focus-indicator mat-raised-button mat-button-base mat-warn')[0].click() }, 1000);
Well, I used this script to delete all users at once in Firebase console:好吧,我使用此脚本在 Firebase 控制台中一次删除所有用户:
$('[aria-label="Delete account"]').each(function() {
$(this).click();
$('[ng-click="controller.submit()"]').click()
})
https://console.firebase.google.com/project/YOUR_PROJECT_NAME/authentication/users https://console.firebase.google.com/project/YOUR_PROJECT_NAME/authentication/users
Updated 03/2022 working (with load next records page)更新 03/2022 工作(加载下一个记录页面)
setInterval(() => {
var RecordsCount = document.getElementsByClassName('edit-account-button mat-focus-indicator mat-menu-trigger mat-icon-button mat-button-base').length;
if (RecordsCount>0)
{
document.getElementsByClassName('edit-account-button mat-focus-indicator mat-menu-trigger mat-icon-button mat-button-base')[0].click()
let deleteButtonPosition = document.getElementsByClassName('mat-focus-indicator mat-menu-item ng-star-inserted').length - 1
document.getElementsByClassName('mat-focus-indicator mat-menu-item ng-star-inserted')[deleteButtonPosition].click()
document.getElementsByClassName('confirm-button mat-focus-indicator mat-raised-button mat-button-base mat-warn')[0].click()
}
else
{
//reload more records
$('[aria-label="Reload"]').first().click();
}
}, 800);
Russian version俄语版
var intervalId; var clearFunction = function() { if ($('[aria-label="Удаление аккаунта"]').size() == 0) { console.log("interval cleared") clearInterval(intervalId) return } $('[aria-label="Удаление аккаунта"]')[0].click(); setTimeout(function () { $('[ng-click="controller.submit()"]').click() }, 1000); }; intervalId = setInterval(clearFunction, 3000)
A solution that worked for me was to create a separate file and import my firebase-admin and simply run the following:一个对我有用的解决方案是创建一个单独的文件并导入我的 firebase-admin 并简单地运行以下命令:
const admin = require('./firebase_admin');
const listAllUsers = () => {
console.log('list all users');
// List batch of users, 1000 at a time.
admin.auth().listUsers(1000)
.then((listUsersResult) => {
listUsersResult.users.forEach((userRecord) => {
const user = userRecord.toJSON();
admin
.auth()
.deleteUser(user.uid)
.then(() => {
console.log('successfully deleted user');
})
.catch((err) => {
console.error('error deleting user: ', err);
});
});
if (listUsersResult.pageToken) {
// List next batch of users.
listAllUsers(listUsersResult.pageToken);
}
})
.catch((error) => {
console.log('Error listing users:', error);
});
};
// Start listing users from the beginning, 1000 at a time.
listAllUsers();
The concept here is that we want to retrieve all the users from our user auth table, then cycle throw and delete them one at a time using the deleteUser admin auth method.这里的概念是我们想从我们的用户身份验证表中检索所有用户,然后使用 deleteUser 管理员身份验证方法一次循环抛出并删除它们。
In the terminal, I simply used node to call the function in the file (so let's say the filename is delete_users.js
, I just called node delete_users.js
and the listUsers function was invoked.在终端中,我只是简单地使用 node 来调用文件中的函数(假设文件名为
delete_users.js
,我只是调用了node delete_users.js
并调用了 listUsers 函数。
Hope this helps.希望这可以帮助。
French version,法语版,
var intervalId;
var clearFunction = function() {
if ($('[aria-label="Supprimer le compte"]').size() == 0) {
console.log("interval cleared")
clearInterval(intervalId)
return
}
$('[aria-label="Supprimer le compte"]')[0].click();
setTimeout(function () {
$(".md-raised:contains(Supprimer)").click()
}, 1000);
};
intervalId = setInterval(clearFunction, 3000)
PS: if you are not web developer and "Execute in tools developer" means nothing to you, here the procedure. PS:如果您不是 Web 开发人员并且“在工具开发人员中执行”对您来说毫无意义,这里是程序。
In the console tab, paste this code and press enter.在控制台选项卡中,粘贴此代码并按 Enter。
If the language matched with the code your paste, account will start to be deleted.如果语言与您粘贴的代码匹配,则帐户将开始被删除。
if u have anonymous accounts如果你有匿名账户
setInterval(() => {
document.getElementsByClassName('edit-account-button mat-focus-indicator mat-menu-trigger mat-icon-button mat-button-base')[0].click()
document.getElementsByClassName('mat-focus-indicator mat-menu-item ng-star-inserted')[document.getElementsByClassName('mat-focus-indicator mat-menu-item ng-star-inserted').length === 3 ? 2 : 1].click()
document.getElementsByClassName('confirm-button mat-focus-indicator mat-raised-button mat-button-base mat-warn')[0].click()
}, 1000)
Just execute the below script on the console and it will delete all users at once.只需在控制台上执行以下脚本,它将立即删除所有用户。
$('.edit-account-button').click();
$('.mat-menu-content button:last-child').click()
$('.fire-dialog-actions .confirm-button').click()
const interval = setInterval(() => {
if ($('.edit-account-button').length === 0) {
clearInterval(interval)
} else {
$('.edit-account-button').first().click()
$('button:contains("Delete account")').click()
$('.confirm-button').click()
}
}, 1000)
https://gist.github.com/cupcakearmy/8c314b891e6958f26374c0205bac85e9 https://gist.github.com/cupcakearmy/8c314b891e6958f26374c0205bac85e9
This Works now 17.09.2021这个作品现在 17.09.2021
Go to your firebase console, click inspect element and select console and paste this code there.转到您的 firebase 控制台,单击检查元素并选择控制台并将此代码粘贴到那里。
setInterval(() => {
document.getElementsByClassName('edit-account-button mat-focus-indicator mat-menu-trigger mat-icon-button mat-button-base')[0].click()
document.getElementsByClassName('mat-focus-indicator mat-menu-item ng-star-inserted')[2].click()
document.getElementsByClassName('confirm-button mat-focus-indicator mat-raised-button mat-button-base mat-warn')[0].click()
}, 1000)
For authentication types: if you authenticate by mail id use [2] in the second line, if you use mobile authentication use 1 in the second line对于身份验证类型:如果您通过邮件 ID 进行身份验证,请在第二行使用 [2],如果您使用移动身份验证,请在第二行使用1
This might be helpful to some.这可能对某些人有帮助。 If you have access to the firebase user console - just save the page as an html and use the following to delete users with node.
如果您有权访问 firebase 用户控制台 - 只需将页面保存为 html 并使用以下命令删除带有 node.js 的用户。 need to setup firebase-admin
需要设置 firebase-admin
let fs = require('fs'),
admin = require('firebase-admin'),
cheerio = require('cheerio');
// initialize firebase admin here
admin.initializeApp({
credential: admin.credential.cert('path/to/serviceAccountKey.json'),
databaseURL: 'https://<DATABASE_NAME>.firebaseio.com'
});
// use cheerio to load the html file you downloaded
$ = cheerio.load(fs.readFileSync('./yourfirebaseconsole.html'));
$('.a12n-user-uid .fb-table-cell-wrapper').each(function() {
admin.auth().deleteUser($(this).text());
}).then(() => {
console.log('successfully delete user');
}).catch((error) => {
console.log('error occurred ', error);
});
I would recommend doing a dry run of the html parsing logic once on the page using browser by just running this and confirming that only user ids are displayed in the result.我建议使用浏览器在页面上运行一次 html 解析逻辑,只需运行它并确认结果中只显示用户 ID。 In my case this returned all UIDs
就我而言,这返回了所有 UID
$('.a12n-user-uid .fb-table-cell-wrapper').each(function() {
console.log($(this).text());
});
I used it我用过
var openMenuItemForFirstUser = function () {
const menuItem = $('[ng-click="controller.deleteUser()"]')
if (menuItem.size()) {
menuItem[0].classList.add("deletingThisUser")
menuItem[0].click();
setTimeout(deleteUser, 10, 0)
} else {
console.log("No users found...")
}
};
var deleteUser = function (t) {
const confirmButton = $('[ng-click="controller.submit()"]')
if (confirmButton.size()) {
console.log("deleting user")
confirmButton[0].click()
setTimeout(waitForDeletion, 10, 0)
} else {
if (t > 500) console.log("fail trying delete user")
else setTimeout(deleteUser, 10, parseInt(t) + 1)
}
}
var waitForDeletion = function (t) {
const deletingThisUser = $('.deletingThisUser')
if (deletingThisUser.size()) {
if (t > 500) console.log("fail wait for deletion")
else setTimeout(waitForDeletion, 10, parseInt(t) + 1)
} else {
setTimeout(openMenuItemForFirstUser, 10)
}
}
setTimeout(openMenuItemForFirstUser, 1000)
console.log("Deleting all users... Press F5 to cancel it")
I tried all the previous, none worked, so I created one for my needs:我尝试了所有以前的方法,都没有奏效,所以我根据需要创建了一个:
setInterval(() => {
if ($('[aria-label="View more options"]').length > 0) {
$('[aria-label="View more options"]')[0].click()
if ($('[role="menuitem"]').length > 0) {
$('[role="menuitem"]')[1].click()
if ($('[class="confirm-button mat-focus-indicator mat-raised-button mat-button-base mat-warn"]').length > 0) {
$('[class="confirm-button mat-focus-indicator mat-raised-button mat-button-base mat-warn"]').click()
}
}
}
}, 500);
Here's another script that can be used as a bookmarklet.这是另一个可以用作书签的脚本。 Simply
简单地
You can then just click the bookmark to delete all users.然后,您只需单击书签即可删除所有用户。 The script will stop when there's no more users or you navigate away.
当没有更多用户或您离开时,脚本将停止。 If you're not using the english version, update the
*Text
variables with the corresponding text.如果您不使用英文版,请使用相应的文本更新
*Text
变量。
javascript: (function () {
const deleteText = 'Delete account';
const deleteConfirmationText = 'Delete';
const editSelector = '.edit-account-button';
const deleteSelector = `button:contains(${deleteText})`;
const deleteConfirmationSelector = `button span:contains(${deleteConfirmationText})`;
const waitForAnimation = 350;
const deleteUsers = () => {
const editAccountButton = $(editSelector).first();
if (!editAccountButton.size()) {
console.log('Delete complete.');
return;
}
editAccountButton.first().click();
setTimeout(() => {
$(deleteSelector).first().click();
setTimeout(() => {
$(deleteConfirmationSelector).first().click();
setTimeout(() => {
deleteUsers();
}, waitForAnimation * 1.5);
}, waitForAnimation);
}, waitForAnimation);
};
deleteUsers();
})();
Just worked here (2021)刚在这里工作 (2021)
var times = 0;
setInterval(() => {
$('.edit-account-button').first().click()
setTimeout(()=>{
$(".mat-button-wrapper:contains(Excluir)").click()
}, 200)
setTimeout(()=>{
$(".mat-menu-item:contains(Excluir)").click()
}, 200)
setTimeout(()=>{
$(".mat-button-wrapper:contains(Excluir)").click()
}, 200)
times++;
console.log(times)
if(times == 150) {
console.log("ATUALIZANDO!!!")
setTimeout(()=>{
$('[aria-label="Atualizar"]').click();
times = 0 ;
}, 200)
}
}, 1000);
with a reload each 150 times, u need just to put in 250每150次重新加载,你只需要放入250
In my project, I had firebaseAdmin hooked up to an emulator for testing.在我的项目中,我将 firebaseAdmin 连接到模拟器进行测试。 To clear the database before each test I combined the
listUsers
function with the deleteUser
function.为了在每次测试之前清除数据库,我将
listUsers
函数与deleteUser
函数结合起来。 Caution you probably don't want to create this type of functionality for a real database.注意你可能不想为真实的数据库创建这种类型的功能。
My code looked like this.我的代码看起来像这样。
import * as Bluebird from "bluebird"
function clearAllUsers() {
return Promise.resolve()
.then(() => admin.auth().listUsers())
.then((response) => response.users)
.then((users) =>
Bluebird.map(users, (user: { uid: string }) =>
admin.auth().deleteUser(user.uid),
),
);
}
But you could also use async await and accomplish the same thing with但是你也可以使用 async await 并完成同样的事情
import * as Bluebird from "bluebird"
async function clearAllUsers() {
const usersResponse = await admin.auth().listUsers();
const users = usersResponse.users;
return await Bluebird.map(users, (user: { uid: string }) =>
admin.auth().deleteUser(user.uid),
);
}
Also if you do happen to use an emulator for testing, the UI for it comes shipped with a delete all button.此外,如果您碰巧使用模拟器进行测试,那么它的 UI 会附带一个全部删除按钮。 see (here)[https://imgur.com/3Xil86I]
见(这里)[https://imgur.com/3Xil86I]
// delete.ts or delete.mjs
import admin from 'firebase-admin';
import cred from './credentials.json';
let firebaseApp = admin.initializeApp({
credential: admin.credential.cert(cred as admin.ServiceAccount)
});
const listAllUsers = (nextPageToken?: string) => {
// List batch of users, 1000 at a time.
admin
.auth()
.listUsers(1000, nextPageToken)
.then(async (listUsersResult) => {
await admin.auth().deleteUsers(listUsersResult.users.map((u) => u.uid));
if (listUsersResult.pageToken) {
// List next batch of users.
listAllUsers(listUsersResult.pageToken);
}
})
.catch((error) => {
console.log('Error listing users:', error);
});
};
listAllUsers();
Thanks for @abbas-ali to sharing this script, it works perfectly fine with the latest firebase release (tested July 2021 with 600+ records - both anonymous and multi federal login email address)感谢 @abbas-ali 分享此脚本,它与最新的 firebase 版本完美配合(2021 年 7 月测试,有 600 多条记录 - 匿名和多联邦登录电子邮件地址)
setInterval(() => {
document.getElementsByClassName('edit-account-button mat-focus-indicator mat-menu-trigger mat-icon-button mat-button-base')[0].click()
if(document.getElementsByClassName('mat-focus-indicator mat-menu-item ng-star-inserted').length===3){
document.getElementsByClassName('mat-focus-indicator mat-menu-item ng-star-inserted')[2].click()
}else{
document.getElementsByClassName('mat-focus-indicator mat-menu-item ng-star-inserted')[1].click()
}
document.getElementsByClassName('confirm-button mat-focus-indicator mat-raised-button mat-button-base mat-warn')[0].click()
}, 1000)
Working on 2022/02/19工作于 2022/02/19
setInterval(() => {
$('[mattooltip="View more options"]').first().click()
setTimeout(()=>{
$(".mat-focus-indicator:contains(Delete)").click()
setTimeout(()=>{
$(".mat-warn").click()
}, 100)
}, 100)
}, 2000);
I wanted to improve yaman-katby answer , because I didn't want to press "refresh button" every time the list was empty.我想改进yaman-katby answer ,因为我不想每次列表为空时都按“刷新按钮” 。
An updated for my answer:我的答案的更新:
So, if you open multiple windows (no fullscreen mode), and order by different ways, you can delete all your users.因此,如果您打开多个窗口(非全屏模式),并以不同的方式排序,您可以删除所有用户。 But sometimes you will find an error that you erased a user previously.
但有时你会发现你之前删除了一个用户的错误。
That why I added times
and elementSize
variables, to refresh the list and continue deleting the users这就是为什么我添加
times
和elementSize
变量,以刷新列表并继续删除用户
let times=0;
let elementSize=0;
setInterval(() => {
if( (document.getElementsByClassName('no-user-text ng-star-inserted').length > 0) || ( elementSize == document.getElementsByClassName('edit-account-button mat-focus-indicator mat-menu-trigger mat-icon-button mat-button-base').length && times == 3 ) || times == 50 ) {
times=0;
elementSize=0;
document.querySelectorAll('.mat-focus-indicator.mat-mdc-tooltip-trigger.mat-icon-button.mat-button-base[data-test-id="reload-user-button"]')[0].click()
} else {
document.getElementsByClassName('edit-account-button mat-focus-indicator mat-menu-trigger mat-icon-button mat-button-base')[0].click();
let deleteButtonPosition = document.getElementsByClassName('mat-focus-indicator mat-menu-item ng-star-inserted').length - 1;
document.getElementsByClassName('mat-focus-indicator mat-menu-item ng-star-inserted')[deleteButtonPosition].click();
document.getElementsByClassName('confirm-button mat-focus-indicator mat-raised-button mat-button-base mat-warn')[0].click();
elementSize = document.getElementsByClassName('edit-account-button mat-focus-indicator mat-menu-trigger mat-icon-button mat-button-base').length;
times++;
}
}, 1000)
Try this,In the browser console.试试这个,在浏览器控制台中。 I couldn't find bulk delete option in firebase.
我在 firebase 中找不到批量删除选项。 So I wrote this js.
所以我写了这个js。
var elements = [];
$('.a12n-users-table').find('tr').each(function(r){
$(this).find('td.table-row-actions').each(function(tds) {
$(this).find('button').each(function(x){
if($(this).attr('aria-label')=="Delete account"){
elements.push($(this));
}
});
});
});
var index = 0;
function deleteUser(){
index++;
elements[index].click();
$('.fb-dialog-actions').find('.md-warn').click();
setTimeout(deleteUser, 5000);
}
deleteUser();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.