-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete-user.mjs
More file actions
39 lines (31 loc) · 1.09 KB
/
delete-user.mjs
File metadata and controls
39 lines (31 loc) · 1.09 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
import { generateClient } from 'aws-amplify/data';
import { Amplify } from 'aws-amplify';
import outputs from './amplify_outputs.json' with { type: 'json' };
Amplify.configure(outputs);
const client = generateClient({
authMode: 'apiKey'
});
async function deleteUser() {
const userId = process.argv[2];
if (!userId) {
console.log('Usage: node delete-user.mjs <user-id>');
console.log('\nListing all users:\n');
const users = await client.models.UserProfile.list();
users.data.forEach((user, index) => {
console.log(`${index + 1}. ${user.email} (${user.role})`);
console.log(` ID: ${user.id}`);
console.log(` UserId: ${user.userId}`);
console.log('');
});
console.log('Run: node delete-user.mjs <ID>');
return;
}
try {
console.log(`Deleting user with ID: ${userId}`);
await client.models.UserProfile.delete({ id: userId });
console.log('✅ User deleted successfully!');
} catch (error) {
console.error('Error:', error);
}
}
deleteUser();