refactor: simplify register flow

This commit is contained in:
Lin, Hung-Shin committed 2023-09-15 15:50:36 +08:00
1 parent 5dd56308ce
commit a6d02f2616
3 files changed
+32 -36

No files matched your search

+13 -3
View File
@@ -67,13 +67,23 @@ export async function register(req, res, next) {
})
return
}
if (await User.exists({ $or: [{ username }, { email }] })) {
if (await User.exists({ username })) {
res.status(409).json({
message: 'username or email already exists',
type: 'username',
message: 'username already exists',
})
console.log(await User.find({ $or: [{ username }, { email }] }))
return
}
if (await User.exists({ email })) {
res.status(409).json({
type: 'email',
message: 'username already exists',
})
return
}
const user = new User({
username,
email,