{"size": 687, "ext": "js", "max_stars_repo_path": "packages/react-scripts/template/server/functions/validateauth.js", "max_stars_repo_name": "CalebBlack/my-create-react-app", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "packages/react-scripts/template/server/functions/validateauth.js", "max_issues_repo_name": "CalebBlack/my-create-react-app", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "packages/react-scripts/template/server/functions/validateauth.js", "max_forks_repo_name": "CalebBlack/my-create-react-app", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 25.4444444444, "max_line_length": 74, "alphanum_fraction": 0.5181950509}
const decodeAuth = require('../functions/decodeauth');

module.exports = function(req,models) {
  return new Promise((resolve,reject)=>{
    var auth = decodeAuth(req);
    if (!auth) {
      reject('Improperly Formatted Auth');
    }
    models.User.find({username:auth.username.toLowerCase()}).then(users=>{
      if (users[0]){
        var user = users[0];
        bcrypt.compare(auth.password, user.hash, function(err, match) {
          if (err || match !== true) {
              reject(err);
            } else {
              resolve(user);
            }
        });
      } else {
        reject("User not found.");
      }
    }).catch(err=>{
      reject(err);
    });
  });
}
