Skip to content

Commit

Permalink
Merge pull request #141 from Emeamos/main
Browse files Browse the repository at this point in the history
adding validationEmail
  • Loading branch information
ExtranoDev authored Sep 23, 2023
2 parents c47d773 + 3614867 commit 466d057
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions controllers/authController.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,29 @@ const User = require('../models/user.model');
const { createCustomError } = require('../errors/custom-errors');
const Organization = require('../models/organization.model');
const OrgLunchWallet = require('../models/org_lunch_wallet.model');

const {sendEmail} = require('./mailController')
const secretKey = process.env.JWT_SECRET_KEY;

async function validateEmail(req, res, next) {
try {
const email = req.body.email;
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;

if (!emailRegex.test(email)) {
throw createCustomError('Invalid email format', 400);
}

await sendEmail(email);

next();
} catch (error) {
console.error(`Error sending email: ${error.message}`);
next(createCustomError('Invalid email', 400));
}
}



async function createUser(req, res, next) {
try {
const {
Expand Down Expand Up @@ -211,4 +231,4 @@ async function createOrgAndUser(req, res, next) {
}
}

module.exports = { createUser, loginUser, logoutUser, createOrgAndUser };
module.exports = { validateEmail, createUser, loginUser, logoutUser, createOrgAndUser };

0 comments on commit 466d057

Please sign in to comment.