Files
Tasks/backend/set-admin-role.js
2025-11-12 23:06:27 +02:00

44 lines
1.1 KiB
JavaScript

const { User } = require('./models');
async function setAdminRole() {
try {
const email = 'admin@example.com';
// Find user by email
const user = await User.findOne({ where: { email } });
if (!user) {
console.log(`User with email ${email} not found`);
console.log('Creating admin user...');
const newUser = await User.create({
email: email,
password: 'Admin123!@#',
username: 'adminuser',
role: 'admin'
});
console.log('✓ Admin user created successfully');
console.log(` ID: ${newUser.id}`);
console.log(` Email: ${newUser.email}`);
console.log(` Role: ${newUser.role}`);
} else {
// Update role to admin
user.role = 'admin';
await user.save();
console.log('✓ User role updated to admin');
console.log(` ID: ${user.id}`);
console.log(` Email: ${user.email}`);
console.log(` Role: ${user.role}`);
}
process.exit(0);
} catch (error) {
console.error('Error:', error.message);
process.exit(1);
}
}
setAdminRole();