send back a specific message per field

Signed-off-by: Ramiro Berrelleza <rberrelleza@gmail.com>
pull/164/head
Ramiro Berrelleza 2021-05-06 12:39:22 -07:00 committed by Ramiro Berrelleza
parent 28dd2421f2
commit d4ba855a72
No known key found for this signature in database
GPG Key ID: 8F443F5203A4B9A3
1 changed files with 11 additions and 2 deletions

View File

@ -7,10 +7,19 @@ export default async function handler(req, res) {
} }
const data = req.body; const data = req.body;
const { username, email, password } = data; 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.'}); res.status(422).json({message: 'Invalid input - password should be at least 7 characters long.'});
return; return;
} }