games-express-api/scripts/adminUser.js

50 lines
1.1 KiB
JavaScript
Raw Normal View History

2024-09-12 15:48:27 -04:00
// noinspection SpellCheckingInspection
import UserModel from '../models/User.js'
// import Bun.password from 'argon2'
import gravatar from 'gravatar'
const createAdmin = async () => {
try {
const hash = await Bun.password.hash('game$databaseadmin1')
const oldUser = await UserModel.findOne({
email: 'admin@gamesdatabase.com',
})
if (oldUser) {
return
}
const avatar = gravatar.url('admin@gamesdatabase.com', {
s: '200',
r: 'pg',
d: 'retro',
})
const user = new UserModel({
name: 'Admin',
email: 'admin@gamesdatabase.com',
password: hash,
displayName: 'Administrator',
avatar,
role: 'admin',
gamesCreated: [],
gamesToAccess: [],
})
await user.save((err) => {
console.log('Admin user successfully created')
if (err) {
return console.error('Could not save admin user')
}
})
} catch (err) {
return console.error(
'Server Error: Could not create admin user' + err.message
)
}
}
export default createAdmin