From d4ba855a72c00f7ebcd9dbddd7af332d91063163 Mon Sep 17 00:00:00 2001 From: Ramiro Berrelleza Date: Thu, 6 May 2021 12:39:22 -0700 Subject: [PATCH] send back a specific message per field Signed-off-by: Ramiro Berrelleza --- pages/api/auth/signup.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pages/api/auth/signup.ts b/pages/api/auth/signup.ts index d2427c0c..d949c7bc 100644 --- a/pages/api/auth/signup.ts +++ b/pages/api/auth/signup.ts @@ -7,10 +7,19 @@ export default async function handler(req, res) { } const data = req.body; - const { username, email, password } = data; - if (!email || !email.includes('@') || !password || password.trim().length < 7) { + if (!username) { + res.status(422).json({message: 'Invalid username'}); + return; + } + + if (!email || !email.includes('@')) { + res.status(422).json({message: 'Invalid email'}); + return; + } + + if (!password || password.trim().length < 7) { res.status(422).json({message: 'Invalid input - password should be at least 7 characters long.'}); return; }