mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-10 02:54:15 +00:00
check existent email on userCreate
This commit is contained in:
parent
30d2c26f34
commit
a28d1433e3
@ -20,14 +20,24 @@ export default async function (payload) {
|
|||||||
throw new Error("Username can only contain letters, numbers, and underscores")
|
throw new Error("Username can only contain letters, numbers, and underscores")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check if username is already taken
|
||||||
const existentUser = await User.findOne({ username: username })
|
const existentUser = await User.findOne({ username: username })
|
||||||
|
|
||||||
if (existentUser) {
|
if (existentUser) {
|
||||||
throw new Error("User already exists")
|
throw new Error("User already exists")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check if the email is already in use
|
||||||
|
const existentEmail = await User.findOne({ email: email })
|
||||||
|
|
||||||
|
if (existentEmail) {
|
||||||
|
throw new Error("Email already in use")
|
||||||
|
}
|
||||||
|
|
||||||
|
// hash the password
|
||||||
const hash = bcrypt.hashSync(password, parseInt(process.env.BCRYPT_ROUNDS ?? 3))
|
const hash = bcrypt.hashSync(password, parseInt(process.env.BCRYPT_ROUNDS ?? 3))
|
||||||
|
|
||||||
|
// create the doc
|
||||||
let user = new User({
|
let user = new User({
|
||||||
username: username,
|
username: username,
|
||||||
password: hash,
|
password: hash,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user