从 firebase 身份验证控制台删除所有用户
Delete all users from firebase auth console
有没有一种简单的方法可以从 firebase 控制台中删除所有注册用户?
例如,我在开发环境中创建了一百个用户,现在我想将其全部删除。
firebaser 在这里
更新 2016-11-08 原回答如下
我们刚刚发布了 Firebase Admin SDK, which supports administrative use-cases, such as deleting a user account without requiring that user to sign in first。
原回答
Firebase 身份验证中目前没有 API 无需用户登录即可删除用户。我们知道这会限制 API 的可用性,并且正在努力在未来的版本。但与往常一样,我们不提供该功能何时可用的具体时间表。
目前你唯一的解决办法是:
- 在应用程序中以每个测试用户的身份登录并从那里删除用户
- 从 Firebase 控制台依次删除每个用户
因为我懒得点击 UI 中的按钮和元素,所以我设置了一个小的客户端脚本:
$('[aria-label="Delete account"]').click()
setTimeout(function () {
$(".md-raised:contains(Delete)").click()
}, 1000);
您可能需要多次 运行,但这比浪费时间手动点击屏幕上的东西要好得多。
稍微增加了你的帮助脚本。
德语 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);
}
对于英文版,只需替换文本即可。
这样一执行就可以删除20个或更多用户
好吧,我使用这个脚本在 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
这可能对某些人有帮助。
如果您有权访问 firebase 用户控制台 - 只需将页面另存为 html 并使用以下命令删除带有节点的用户。需要设置 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);
});
我建议使用浏览器在页面上对 html 解析逻辑进行干 运行 一次,方法是 运行ning 并确认只有用户 ID 显示在结果。在我的例子中,这返回了所有 UID
$('.a12n-user-uid .fb-table-cell-wrapper').each(function() {
console.log($(this).text());
});
如更新后的答案一样,您现在可能可以使用 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)
只需运行在开发者工具中
俄语版
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)
setInterval(() => {
$('[aria-label="Delete account"]').first().click()
setTimeout(()=>{
$(".md-raised:contains(Delete)").click()
}, 100)
}, 2000);
旨在避免经常调用 delete
端点,因为 google 失败并出现 404
错误。
我用过
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")
使用 Firebase Admin SDK 的完整解决方案
使用 Firebase Admin SDK 非常简单并且推荐方法对您的 Firebase 数据执行此类任务。此解决方案不同于其他使用开发人员控制台的临时解决方案。
我只是整理了一个 Node.js 脚本来删除您的 Firebase 身份验证中的所有用户。我已经通过删除 ~10000 个用户对其进行了测试。我只是 运行 以下 Node.js 代码。
设置 Firebase Admin SDK
创建一个新文件夹。 运行终端中的以下内容
npm init
sudo npm install firebase-admin --save
现在在此文件夹中创建一个 index.js
文件。
要遵循的步骤:
- 转到您的 Firebase 项目 -> 项目设置 -> 服务帐户。
- 单击
Generate new Private Key
下载 JSON 文件。复制 JSON 文件的路径,并将其替换为服务帐户私钥 json 文件路径中的以下代码。
- 此外,从设置页面复制
databaseURL
。在代码中替换它。
- 复制并粘贴
index.js
中的代码。
- 运行 在航站楼
node index.js
。观看混乱!
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();
一个对我有用的解决方案是创建一个单独的文件并导入我的 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();
这里的概念是我们要从我们的用户身份验证 table 中检索所有用户,然后循环抛出并使用 deleteUser 管理身份验证方法一次一个地删除它们。
在终端中,我只是简单地使用节点来调用文件中的函数(假设文件名为 delete_users.js
,我只是调用了 node delete_users.js
并调用了 listUsers 函数。
希望对您有所帮助。
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);
试试这个。这是对上述@www.eugenehp.tk 回答的更新,考虑到如果您有多个条目,则需要刷新页面。
试试这个,在浏览器控制台中。我在 firebase 中找不到批量删除选项。所以我写了这个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();
法语版,
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:如果您不是 Web 开发人员并且 "Execute in tools developer" 对您来说毫无意义,这里是程序。
- 使用 Chrome
打开您的 firebase authentication/users 页面
- 按control + shif+ J
在控制台选项卡中,粘贴此代码并按回车键。
如果语言与您粘贴的代码匹配,将开始删除帐户。
对于新的 Firebase 更新
尝试使用此代码获取最新的 Firebase 更新。
打开控制台,粘贴此代码并按回车键!!!
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)
在 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);
我尝试了之前的所有方法,none 成功了,所以我创建了一个以满足我的需要:
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);
这是另一个可以用作小书签的脚本。简直
- 创建新书签 (Ctrl-D)
- select“更多”'
- 将脚本粘贴到 URL 输入
然后您只需单击书签即可删除所有用户。当没有更多用户或您导航离开时,脚本将停止。如果您使用的不是英文版,请使用相应的文本更新 *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();
})();
如果你有匿名账户
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)
只需在控制台执行以下脚本即可一次性删除所有用户。
$('.edit-account-button').click();
$('.mat-menu-content button:last-child').click()
$('.fire-dialog-actions .confirm-button').click()
刚在这里工作 (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);
每150次重新加载一次,你只需要输入250
更新了 2021 年工作答案
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
在我的项目中,我将 firebaseAdmin 连接到模拟器进行测试。为了在每次测试前清除数据库,我将 listUsers
函数与 deleteUser
函数组合在一起。 警告您可能不想为真实数据库创建此类功能。
我的代码是这样的。
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),
),
);
}
但您也可以使用 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),
);
}
此外,如果您碰巧使用模拟器进行测试,UI 附带一个删除所有按钮。请参阅(此处)[https://imgur.com/3Xil86I]
简单删除所有用户 - ESM
// 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();
感谢@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)
现在有效 17.09.2021
转到您的 firebase 控制台,单击检查元素和 select 控制台并将此代码粘贴到那里。
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)
对于身份验证类型:
如果您通过邮件 ID 进行身份验证,请在第二行使用 [2],
如果您使用移动身份验证,请在第二行使用1
2021 年 10 月 10 日测试
这将单击上下文菜单中的最后一个按钮,该按钮始终是删除按钮,因此它适用于所有帐户类型
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);
2022/02/19 工作
setInterval(() => {
$('[mattooltip="View more options"]').first().click()
setTimeout(()=>{
$(".mat-focus-indicator:contains(Delete)").click()
setTimeout(()=>{
$(".mat-warn").click()
}, 100)
}, 100)
}, 2000);
更新 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);
我想改进,因为我不想每次都按“刷新按钮”列表为空。
更新我的回答:
因此,如果您打开多个 windows(非全屏模式),并通过不同的方式排序,您可以删除所有用户。但有时你会发现你之前删除了一个用户的错误。
这就是我添加 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)
有没有一种简单的方法可以从 firebase 控制台中删除所有注册用户? 例如,我在开发环境中创建了一百个用户,现在我想将其全部删除。
firebaser 在这里
更新 2016-11-08 原回答如下
我们刚刚发布了 Firebase Admin SDK, which supports administrative use-cases, such as deleting a user account without requiring that user to sign in first。
原回答
Firebase 身份验证中目前没有 API 无需用户登录即可删除用户。我们知道这会限制 API 的可用性,并且正在努力在未来的版本。但与往常一样,我们不提供该功能何时可用的具体时间表。
目前你唯一的解决办法是:
- 在应用程序中以每个测试用户的身份登录并从那里删除用户
- 从 Firebase 控制台依次删除每个用户
因为我懒得点击 UI 中的按钮和元素,所以我设置了一个小的客户端脚本:
$('[aria-label="Delete account"]').click()
setTimeout(function () {
$(".md-raised:contains(Delete)").click()
}, 1000);
您可能需要多次 运行,但这比浪费时间手动点击屏幕上的东西要好得多。
稍微增加了你的帮助脚本。
德语 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);
}
对于英文版,只需替换文本即可。 这样一执行就可以删除20个或更多用户
好吧,我使用这个脚本在 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
这可能对某些人有帮助。 如果您有权访问 firebase 用户控制台 - 只需将页面另存为 html 并使用以下命令删除带有节点的用户。需要设置 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);
});
我建议使用浏览器在页面上对 html 解析逻辑进行干 运行 一次,方法是 运行ning 并确认只有用户 ID 显示在结果。在我的例子中,这返回了所有 UID
$('.a12n-user-uid .fb-table-cell-wrapper').each(function() {
console.log($(this).text());
});
如更新后的答案一样,您现在可能可以使用 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)
只需运行在开发者工具中
俄语版
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)
setInterval(() => {
$('[aria-label="Delete account"]').first().click()
setTimeout(()=>{
$(".md-raised:contains(Delete)").click()
}, 100)
}, 2000);
旨在避免经常调用 delete
端点,因为 google 失败并出现 404
错误。
我用过
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")
使用 Firebase Admin SDK 的完整解决方案
使用 Firebase Admin SDK 非常简单并且推荐方法对您的 Firebase 数据执行此类任务。此解决方案不同于其他使用开发人员控制台的临时解决方案。
我只是整理了一个 Node.js 脚本来删除您的 Firebase 身份验证中的所有用户。我已经通过删除 ~10000 个用户对其进行了测试。我只是 运行 以下 Node.js 代码。
设置 Firebase Admin SDK
创建一个新文件夹。 运行终端中的以下内容
npm init
sudo npm install firebase-admin --save
现在在此文件夹中创建一个 index.js
文件。
要遵循的步骤:
- 转到您的 Firebase 项目 -> 项目设置 -> 服务帐户。
- 单击
Generate new Private Key
下载 JSON 文件。复制 JSON 文件的路径,并将其替换为服务帐户私钥 json 文件路径中的以下代码。 - 此外,从设置页面复制
databaseURL
。在代码中替换它。 - 复制并粘贴
index.js
中的代码。 - 运行 在航站楼
node index.js
。观看混乱!
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();
一个对我有用的解决方案是创建一个单独的文件并导入我的 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();
这里的概念是我们要从我们的用户身份验证 table 中检索所有用户,然后循环抛出并使用 deleteUser 管理身份验证方法一次一个地删除它们。
在终端中,我只是简单地使用节点来调用文件中的函数(假设文件名为 delete_users.js
,我只是调用了 node delete_users.js
并调用了 listUsers 函数。
希望对您有所帮助。
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);
试试这个。这是对上述@www.eugenehp.tk 回答的更新,考虑到如果您有多个条目,则需要刷新页面。
试试这个,在浏览器控制台中。我在 firebase 中找不到批量删除选项。所以我写了这个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();
法语版,
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:如果您不是 Web 开发人员并且 "Execute in tools developer" 对您来说毫无意义,这里是程序。
- 使用 Chrome 打开您的 firebase authentication/users 页面
- 按control + shif+ J
在控制台选项卡中,粘贴此代码并按回车键。
如果语言与您粘贴的代码匹配,将开始删除帐户。
对于新的 Firebase 更新
尝试使用此代码获取最新的 Firebase 更新。 打开控制台,粘贴此代码并按回车键!!!
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)
在 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);
我尝试了之前的所有方法,none 成功了,所以我创建了一个以满足我的需要:
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);
这是另一个可以用作小书签的脚本。简直
- 创建新书签 (Ctrl-D)
- select“更多”'
- 将脚本粘贴到 URL 输入
然后您只需单击书签即可删除所有用户。当没有更多用户或您导航离开时,脚本将停止。如果您使用的不是英文版,请使用相应的文本更新 *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();
})();
如果你有匿名账户
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)
只需在控制台执行以下脚本即可一次性删除所有用户。
$('.edit-account-button').click();
$('.mat-menu-content button:last-child').click()
$('.fire-dialog-actions .confirm-button').click()
刚在这里工作 (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);
每150次重新加载一次,你只需要输入250
更新了 2021 年工作答案
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
在我的项目中,我将 firebaseAdmin 连接到模拟器进行测试。为了在每次测试前清除数据库,我将 listUsers
函数与 deleteUser
函数组合在一起。 警告您可能不想为真实数据库创建此类功能。
我的代码是这样的。
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),
),
);
}
但您也可以使用 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),
);
}
此外,如果您碰巧使用模拟器进行测试,UI 附带一个删除所有按钮。请参阅(此处)[https://imgur.com/3Xil86I]
简单删除所有用户 - ESM
// 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();
感谢@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)
现在有效 17.09.2021
转到您的 firebase 控制台,单击检查元素和 select 控制台并将此代码粘贴到那里。
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)
对于身份验证类型: 如果您通过邮件 ID 进行身份验证,请在第二行使用 [2], 如果您使用移动身份验证,请在第二行使用1
2021 年 10 月 10 日测试
这将单击上下文菜单中的最后一个按钮,该按钮始终是删除按钮,因此它适用于所有帐户类型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);
2022/02/19 工作
setInterval(() => {
$('[mattooltip="View more options"]').first().click()
setTimeout(()=>{
$(".mat-focus-indicator:contains(Delete)").click()
setTimeout(()=>{
$(".mat-warn").click()
}, 100)
}, 100)
}, 2000);
更新 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);
我想改进
更新我的回答:
因此,如果您打开多个 windows(非全屏模式),并通过不同的方式排序,您可以删除所有用户。但有时你会发现你之前删除了一个用户的错误。
这就是我添加 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)