-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathresetAdmin.js
More file actions
33 lines (27 loc) · 846 Bytes
/
resetAdmin.js
File metadata and controls
33 lines (27 loc) · 846 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
const mongoose = require("mongoose")
const dotenv = require("dotenv")
const User = require("./models/User")
dotenv.config()
const resetAdmin = async () => {
try {
await mongoose.connect(process.env.MONGODB_URI)
console.log("✅ MongoDB Connected")
// Delete old admin if exists
await User.deleteOne({ username: "admin" })
// Create admin with plain text password (will be hashed by pre-save hook)
const admin = new User({
username: "admin",
email: "admin@test.com",
password: "password",
fullName: "System Administrator",
role: "Admin",
})
await admin.save()
console.log("🎉 Admin reset: username=admin, password=password")
process.exit()
} catch (err) {
console.error("❌ Error:", err)
process.exit(1)
}
}
resetAdmin()