-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathadmin.js
More file actions
46 lines (41 loc) · 1.24 KB
/
admin.js
File metadata and controls
46 lines (41 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const admin = require('firebase-admin');
const readline = require('readline');
const fs = require("fs")
const os = require('os');
const path = require('path');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
// Directory and file paths
const dirPath = path.join(os.homedir(), '.cleanslate');
const filePath = path.join(dirPath, 'users.json');
if (!fs.existsSync(dirPath)) {
fs.mkdirSync(dirPath, { recursive: true });
}
rl.question('Enter your Firebase project ID: ', (projectId) => {
admin.initializeApp({
credential: admin.credential.applicationDefault(),
projectId: projectId.trim()
});
const users = []
async function listAllUsers(nextPageToken) {
try {
const result = await admin.auth().listUsers(1000, nextPageToken);
result.users.forEach((userRecord) => {
users.push(userRecord)
});
if (result.pageToken) {
await listAllUsers(result.pageToken);
} else {
console.log('✅ Finished listing all users.');
fs.writeFileSync(filePath, JSON.stringify(users, undefined, 2))
rl.close();
}
} catch (error) {
console.error('❌ Error listing users:', error);
rl.close();
}
}
listAllUsers();
});