Commit 216f9dfb authored by AravindR-K's avatar AravindR-K

feat: implement MongoDB connection and default admin user initialization

parent 80147bab
const mongoose = require('mongoose'); const mongoose = require('mongoose');
const User = require('../models/User'); const User = require('../models/User');
const bcrypt = require('bcryptjs');
const createAdmin = async () => { const createAdmin = async () => {
const adminExists = await User.findOne({ email: 'admin@test.com' }); const adminExists = await User.findOne({ email: 'admin@quizapp.com' });
if (!adminExists) { if (!adminExists) {
const hashedPassword = await bcrypt.hash('admin123', 10); // Pass plain password - User model's pre-save hook will hash it
await User.create({ await User.create({
name: 'Admin', name: 'Admin',
email: 'admin@test.com', email: 'admin@quizapp.com',
password: hashedPassword, password: 'admin123',
role: 'admin' role: 'admin'
}); });
console.log('Default admin created'); console.log('Default admin created: admin@quizapp.com / admin123');
} }
}; };
const connectDB = async () => { const connectDB = async () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment