-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-admin.js
More file actions
47 lines (40 loc) · 1.11 KB
/
Copy pathcreate-admin.js
File metadata and controls
47 lines (40 loc) · 1.11 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
const { getPayload } = require('payload');
const config = require('./src/payload.config.simple');
async function createAdminUser() {
try {
const payload = await getPayload({
config,
});
// Check if admin user already exists
const existingAdmin = await payload.find({
collection: 'users',
where: {
email: {
equals: 'admin@modernmen.com'
}
}
});
if (existingAdmin.docs.length > 0) {
console.log('Admin user already exists');
return;
}
// Create admin user
const adminUser = await payload.create({
collection: 'users',
data: {
email: 'admin@modernmen.com',
name: 'Modern Men Admin',
role: 'admin',
password: 'admin123'
}
});
console.log('Admin user created successfully:', adminUser.email);
console.log('Password: admin123');
console.log('Please change the password after first login!');
} catch (error) {
console.error('Error creating admin user:', error);
} finally {
process.exit(0);
}
}
createAdminUser();