-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseedadmin.js
More file actions
38 lines (30 loc) · 933 Bytes
/
seedadmin.js
File metadata and controls
38 lines (30 loc) · 933 Bytes
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
import mongoose from 'mongoose';
import bcrypt from 'bcrypt';
import User from './src/models/User.js';
async function seedAdmin() {
try {
await mongoose.connect(process.env.MONGO_URI);
console.log(' Connected to MongoDB');
const existingAdmin = await User.findOne({ role: 'admin' });
if (existingAdmin) {
console.log('Admin user already exists:', existingAdmin.email);
return process.exit(0);
}
const hashedPassword = await bcrypt.hash('Admin@123', 10);
const adminUser = new User({
email: 'admin@gmail.com',
password: hashedPassword,
role: 'admin',
name: 'Super Admin',
phno: '9999999999',
status: 'Active'
});
await adminUser.save();
console.log('Admin user created successfully:', adminUser.email);
process.exit(0);
} catch (err) {
console.error('Error seeding admin user:', err);
process.exit(1);
}
}
seedAdmin();