mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-10 02:54:15 +00:00
added createUser
to lib
This commit is contained in:
parent
81167c455e
commit
cde9caa24b
28
packages/server/src/lib/createUser/index.js
Normal file
28
packages/server/src/lib/createUser/index.js
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import { User } from "../../models"
|
||||||
|
import Avatars from "dicebar_lib"
|
||||||
|
import bcrypt from "bcrypt"
|
||||||
|
|
||||||
|
export default async function (payload) {
|
||||||
|
let { username, password, email, fullName, roles, avatar } = payload
|
||||||
|
|
||||||
|
const existentUser = await User.findOne({ username: username })
|
||||||
|
|
||||||
|
if (existentUser) {
|
||||||
|
throw new Error("User already exists")
|
||||||
|
}
|
||||||
|
|
||||||
|
const hash = bcrypt.hashSync(password, parseInt(process.env.BCRYPT_ROUNDS ?? 3))
|
||||||
|
|
||||||
|
let user = new User({
|
||||||
|
username: username,
|
||||||
|
password: hash,
|
||||||
|
email: email,
|
||||||
|
fullName: fullName,
|
||||||
|
avatar: avatar ?? Avatars.generate({ seed: username, type: "initials" }).uri,
|
||||||
|
roles: roles,
|
||||||
|
})
|
||||||
|
|
||||||
|
user.save()
|
||||||
|
|
||||||
|
return user
|
||||||
|
}
|
@ -1,3 +1,5 @@
|
|||||||
export * as Token from './token'
|
export { default as Schematized } from "./schematized"
|
||||||
export { default as Schematized } from './schematized'
|
export { default as additionsHandler } from "./additionsHandler"
|
||||||
export { default as additionsHandler } from './additionsHandler'
|
export { default as createUser } from "./createUser"
|
||||||
|
|
||||||
|
export * as Token from "./token"
|
Loading…
x
Reference in New Issue
Block a user