Files
games-express-api/scripts/adminUser.js
T
john-okeefe 0adf0bd51f
Release / build-and-push (push) Successful in 1m14s
fix(admin): await user.save() without callback in createAdmin
Mongoose 7 removed callback support on Model.prototype.save(),
so the seeder threw 'no longer accepts a callback' on every
boot (caught and logged, non-fatal, but noisy and the success
path never ran). Await the promise and log on success.
2026-09-05 22:48:53 -04:00

46 lines
976 B
JavaScript

// 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()
console.log('Admin user successfully created')
} catch (err) {
return console.error(
'Server Error: Could not create admin user' + err.message
)
}
}
export default createAdmin