{"size": 782, "ext": "js", "max_stars_repo_path": "utils/login.js", "max_stars_repo_name": "elPoeta/social-dev-react-express", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "utils/login.js", "max_issues_repo_name": "elPoeta/social-dev-react-express", "max_issues_repo_issues_event_min_datetime": "2020-07-16T19:11:10.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-08T06:48:56.000Z", "max_forks_repo_path": "utils/login.js", "max_forks_repo_name": "elPoeta/social-dev-react-express", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 2, "max_forks_count": null, "avg_line_length": 25.2258064516, "max_line_length": 65, "alphanum_fraction": 0.5959079284}
const Validator = require('validator');
const isEmpty = require('./isEmpty');

module.exports = validateLoginInput = (req, res, next) => {
    let errors = {};

    const data = req.body;

    data.email = !isEmpty(data.email) ? data.email : '';
    data.password = !isEmpty(data.password) ? data.password : '';

    if (!Validator.isEmail(data.email)) {
        errors.email = 'Email is invalid';
    }

    if (Validator.isEmpty(data.email)) {
        errors.email = 'Email field is required';
    }

    if (Validator.isEmpty(data.password)) {
        errors.password = 'Password field is required';
    }
    if (!isEmpty(errors)) {
        return res.status(400).json(errors);
    }
    if (!isEmpty(errors)) {
        return res.status(400).json(errors);
    }
    next();

};