-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcleanup-users.mjs
More file actions
65 lines (55 loc) · 2.47 KB
/
cleanup-users.mjs
File metadata and controls
65 lines (55 loc) · 2.47 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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 cleanupDuplicates() {
console.log('Fetching all users...\n');
try {
const users = await client.models.UserProfile.list();
const jamieCecilUsers = users.data.filter(u => u.email === 'jamiececil@gmail.com');
if (jamieCecilUsers.length === 0) {
console.log('No users found with email jamiececil@gmail.com');
return;
}
console.log(`Found ${jamieCecilUsers.length} user(s) with email jamiececil@gmail.com:\n`);
jamieCecilUsers.forEach((user, index) => {
console.log(`${index + 1}. ID: ${user.id}`);
console.log(` UserId: ${user.userId}`);
console.log(` Name: ${user.name || 'No name'}`);
console.log(` Role: ${user.role}`);
console.log('');
});
// Find the manual one (has 'manual-admin' in userId)
const manualUser = jamieCecilUsers.find(u => u.userId.startsWith('manual-admin'));
const realUser = jamieCecilUsers.find(u => !u.userId.startsWith('manual-admin'));
if (manualUser && realUser) {
console.log('Deleting the manual duplicate...');
await client.models.UserProfile.delete({ id: manualUser.id });
console.log('✅ Deleted manual duplicate!');
console.log('\nUpdating real user to ADMIN...');
await client.models.UserProfile.update({
id: realUser.id,
role: 'ADMIN'
});
console.log('✅ Updated real user to ADMIN!');
console.log('\nYou now have one user with ADMIN role.');
console.log('Log out and log back in to access /admin');
} else if (jamieCecilUsers.length > 1) {
console.log('Multiple users found, but cannot determine which is duplicate.');
console.log('Please manually delete one using the ID above.');
} else {
console.log('Only one user found. Ensuring ADMIN role...');
await client.models.UserProfile.update({
id: jamieCecilUsers[0].id,
role: 'ADMIN'
});
console.log('✅ Updated to ADMIN!');
}
} catch (error) {
console.error('Error:', error);
}
}
cleanupDuplicates();