Skip to content

Commit

Permalink
Backend_Mail_Validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Shrinaya S K committed May 28, 2024
1 parent 35a342b commit 515c584
Show file tree
Hide file tree
Showing 5 changed files with 493 additions and 138 deletions.
23 changes: 12 additions & 11 deletions assets/validation/validate.schema.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
const validate = (schema) => async (req, res, next) => {
try {
const parsedBody = await schema.parseAsync(req.body);
req.body = parsedBody;
next();
const parsedBody = await schema.parseAsync(req.body);
req.body = parsedBody;
next();
} catch (err) {
console.log(err);
const yourerror = err.errors[0].message;
res.status(400).json({
msg: yourerror,
});
console.log(err);
const yourerror = err.errors[0].message;
res.status(400).json({
msg: yourerror,
});
}
}

module.exports = validate;
}

module.exports = validate;

1 change: 1 addition & 0 deletions assets/validation/zodschema.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const RegisterSchema = zod.object({
.string({ required_error: 'Email is required' })
.trim()
.email({ message: 'Invalid Email Address' })
.regex(/^[a-zA-Z0-9._%+-]+@gmail\.com$/, { message: 'Email must be a Gmail address ending with @gmail.com' })
.min(3, { message: 'Email should be at least 3 characters' })
.max(255, { message: 'Email can be at most 255 characters' }),
password: zod
Expand Down
Loading

0 comments on commit 515c584

Please sign in to comment.