Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 24 additions & 18 deletions server/controllers/auth.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,40 +196,46 @@ class AuthController extends Controller {

async validateBeforeCreateAccount(req, res, next) {
const user = req.body.user;

if (!user) {
return next(new BadRequestException("User is not provider"));
}
const { email, password } = user;

const errors = [];

if (!email || !password) {
const errors = [];
if (!email) {
errors.push({
field: "email",
message: "Email is not empty!",
field: 'email',
message: 'Email is empty!',
});
}

if (!password) {
errors.push({
field: "password",
message: "Password is not empty!",
field: 'password',
message: 'Password is empty!',
});
}
}

if (password.length < MIN_LENGTH_PASS) {
errors.push({
field: "password",
message: "Password must be greater than or equal to 8 characters!",
});
}
if (password.length < MIN_LENGTH_PASS) {
errors.push({
field: 'password',
message: 'Password must be greater than or equal to ' + MIN_LENGTH_PASS + ' characters!',
});
}

if (!REGEX_EMAIL.test(email)) {
errors.push({
field: "email",
message: "Email invalid!",
});
}
return next(new NotFoundException("failure", errors));
if (!REGEX_EMAIL.test(email)) {
errors.push({
field: 'email',
message: 'Email invalid!',
});
}

if (errors.length > 0) {
return next(new NotFoundException('Missing or incorrect information', errors));
}

next();
Expand Down