1
0
forked from noxious/server

Add email field and add it to register logic

This commit is contained in:
2024-10-27 17:25:45 +01:00
parent 6a1823586a
commit 8f8f019ab7
6 changed files with 31 additions and 4 deletions

View File

@ -33,16 +33,22 @@ class UserService {
* @param username
* @param password
*/
async register(username: string, password: string): Promise<boolean | User> {
async register(username: string, email: string, password: string): Promise<boolean | User> {
const user = await UserRepository.getByUsername(username)
if (user) {
return false
}
const userByEmail = await UserRepository.getByEmail(email)
if (userByEmail) {
return false
}
const hashedPassword = await bcrypt.hash(password, 10)
return prisma.user.create({
data: {
username,
email,
password: hashedPassword
}
})