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

@ -40,16 +40,16 @@ async function addHttpRoutes(app: Application) {
* @param res
*/
app.post('/register', async (req: Request, res: Response) => {
const { username, password } = req.body
const { username, email, password } = req.body
try {
registerAccountSchema.parse({ username, password })
registerAccountSchema.parse({ username, email, password })
} catch (error: any) {
return res.status(400).json({ message: error.errors[0]?.message })
}
const userService = new UserService()
const user = await userService.register(username, password)
const user = await userService.register(username, email, password)
if (user) {
return res.status(200).json({ message: 'User registered' })