<commit_before>'use strict';

const tokenSvc = require('./token');

module.exports = function getEnsureAuth() {
  return function ensureAuth(req, res, next) {
    const token = req.headers.authorization;
    if(!token) return next({ code: 400, error: 'Unauthorized, no token provided'});
    console.log('Inside ensureAuth, about to verify token');
    tokenSvc.verify(token)
      .then(payload => {
        req.user = payload;
        next();
      })
      .catch(err => {
        console.log('inside ensureAuth catch: ', err);
        next({ code: 403, error: 'Unauthorized, bad token'});
      });
  };
};<commit_msg>Fixing tests<commit_after>'use strict';

const tokenSvc = require('./token');

module.exports = function getEnsureAuth() {
  return function ensureAuth(req, res, next) {
    const token = req.headers.authorization;
    if(!token) return next({ code: 400, error: 'Unauthorized, no token provided'});
    tokenSvc.verify(token)
      .then(payload => {
        req.user = payload;
        next();
      })
      .catch(err => { //eslint-disable-line
        next({ code: 403, error: 'Unauthorized, bad token'});
      });
  };
};
{'fraction_non_alphanumeric': 0.15752828546562228, 'fraction_numerical': 0.010443864229765013, 'mean_word_length': 3.020979020979021, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4590262', 'n_tokens_mistral': 357, 'n_tokens_neox': 344, 'n_words': 90}