Merge pull request #164 from rberrelleza/split-signup-validation

send back a specific message per field
This commit is contained in:
Bailey Pumfleet 2021-05-06 21:48:04 +01:00 committed by GitHub
commit 9032adb9ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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;
}