Release / build-and-push (push) Successful in 1m14s
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.
46 lines
976 B
JavaScript
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
|