You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

31 lines
767 B

import {getUserByEmailServices} from "../services/users.services.js";
export async function doUserAlreadyExists(req,res,next){
const email = req.body.email;
const request = await getUserByEmailServices(email);
if (request.rows && request.rows.length > 0) {
return res.status(409).json({
error: 409,
message: `Email already exists`,
})
}
next();
}
export async function doUserExists(req,res,next){
console.log(req.body);
const email = req.body.email;
const request = await getUserByEmailServices(email);
if (request.rows && request.rows.length > 0) {
next()
} else {
return res.json({
error: 401,
message: 'Bad Credentials'
})
}
}