-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake-admin.mjs
More file actions
63 lines (52 loc) · 2.18 KB
/
make-admin.mjs
File metadata and controls
63 lines (52 loc) · 2.18 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
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 listAndMakeAdmin() {
console.log('Fetching all users...\n');
try {
const users = await client.models.UserProfile.list();
if (users.data.length === 0) {
console.log('No users found in database.');
console.log('\nCreating admin profile for jamiececil@gmail.com...');
// Create admin profile manually
const newAdmin = await client.models.UserProfile.create({
userId: 'manual-admin-' + Date.now(), // Temporary userId
email: 'jamiececil@gmail.com',
name: 'Jamie Cecil',
role: 'ADMIN'
});
console.log('✅ Created admin profile!');
console.log('Note: You may need to update the userId after next login.');
return;
}
console.log(`Found ${users.data.length} user(s):\n`);
users.data.forEach((user, index) => {
console.log(`${index + 1}. ${user.name || 'No name'} (${user.email}) - Role: ${user.role}`);
});
// Auto-promote first user to admin if email matches
const targetUser = users.data.find(u => u.email === 'jamiececil@gmail.com');
if (targetUser) {
console.log(`\nPromoting ${targetUser.email} to ADMIN...`);
await client.models.UserProfile.update({
id: targetUser.id,
role: 'ADMIN'
});
console.log('✅ Successfully promoted to ADMIN!');
} else {
console.log('\njamiececil@gmail.com not found. Promoting first user to admin...');
const firstUser = users.data[0];
await client.models.UserProfile.update({
id: firstUser.id,
role: 'ADMIN'
});
console.log(`✅ Promoted ${firstUser.email} to ADMIN!`);
}
} catch (error) {
console.error('Error:', error);
}
}
listAndMakeAdmin();