<commit_before>'use strict';
var db = require('../models');
var _ = require('lodash');
var config = require('config');
var logger = require('../utils/logger');
module.exports = function(req, res, next) {
    if (req.method === 'OPTIONS') {
        return next();
    }
    var t = req.get('Authorization');
    var unauthorization = config.get('unauthorization');
    if (_.indexOf(unauthorization, req.url) < 0){
        if (t === undefined) {
            logger.info('Access Denied');
            res.status(401).send(JSON.stringify({}));
            return next();
        }
        t = t.replace('Bearer ', '');
        db.Token.findOne({
            where: {
                token: t
            }
        }).then(function(token){
            if (!token){
                throw('');
            }
        }).catch(function(){
            logger.info('Access Denied');
            res.status(401).send(JSON.stringify({}));
        });
    } else {
        next();
    }
};<commit_msg>bug auth<commit_after>'use strict';
var db = require('../models');
var _ = require('lodash');
var config = require('config');
var logger = require('../utils/logger');
module.exports = function(req, res, next) {
    if (req.method === 'OPTIONS') {
        return next();
    }
    var t = req.get('Authorization');
    var unauthorization = config.get('unauthorization');
    if (_.indexOf(unauthorization, req.url) < 0){
        if (t === undefined) {
            logger.info('Access Denied');
            res.status(401).send(JSON.stringify({}));
            return next();
        }
        t = t.replace('Bearer ', '');
        db.Token.findOne({
            where: {
                token: t
            }
        }).then(function(token){
            if (!token){
                throw('');
            } else {
                return next();
            }
        }).catch(function(){
            logger.info('Access Denied');
            res.status(401).send(JSON.stringify({}));
        });
    } else {
        next();
    }
};
{'fraction_non_alphanumeric': 0.17943648047454275, 'fraction_numerical': 0.006920415224913495, 'mean_word_length': 1.768809849521204, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '2459894', 'n_tokens_mistral': 587, 'n_tokens_neox': 569, 'n_words': 116}