moved api from monorepo
This commit is contained in:
49
scripts/adminUser.js
Normal file
49
scripts/adminUser.js
Normal file
@ -0,0 +1,49 @@
|
||||
// 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
|
Reference in New Issue
Block a user