<commit_before>const JwtStrategy = require('passport-jwt').Strategy,
    LocalStrategy = require('passport-local').Strategy,
    ExtractJwt = require('passport-jwt').ExtractJwt;

// Get user model
const User = require('../models/user');
const config = require('../config/config');

module.exports = function(passport) {
    var opts = {};
    opts.jwtFromRequest = ExtractJwt.fromAuthHeader();
    opts.secretOrKey = config.secret;
    passport.use(new JwtStrategy(opts, function(jwt_payload, done) {
        User.findOne({ _id: jwt_payload._id }, function(err, user) {
            if (err) return done(err, false);
            if (user) {
                if (user.loginError()) done(null, false, { error: user.loginError() });                
                return done(null, user);
            }
            done(null, false, { error: { message: "Invalid token.", code: "invalid_token" } });
        });
    }));

    passport.use(new LocalStrategy(function(username, password, done) {
        User.findOne({ name: username }, function(err, user) {
            if (err) return done(err, false);
            if (user) {
                if (user.loginError()) done(null, false, { error: user.loginError() });
                return user.comparePassword(password, function(err, match) {
                    if (match && !err) return done(null, user);
                    done(null, false, { error: { message: "Incorrect username or password provided.", code: "invalid_credentials" } });
                });
            }
            done(null, false, { error: { message: "Incorrect username or password provided.", code: "invalid_credentials" } });
        });
    }));

    passport.serializeUser(function(user, done) {
        done(null, user.id);
    });

    passport.deserializeUser(function(user, done) {
        User.findById(user, (err, user) => done(err, user));
    });
}<commit_msg>Another broken API endpoint<commit_after>const JwtStrategy = require('passport-jwt').Strategy,
    LocalStrategy = require('passport-local').Strategy,
    ExtractJwt = require('passport-jwt').ExtractJwt;

// Get user model
const User = require('../models/user');
const config = require('../config/config');

module.exports = function(passport) {
    var opts = {};
    opts.jwtFromRequest = ExtractJwt.fromAuthHeader();
    opts.secretOrKey = config.secret;
    passport.use(new JwtStrategy(opts, function(jwt_payload, done) {
        User.findOne({ _id: jwt_payload._id }, function(err, user) {
            if (err) return done(err, false);
            if (user) {
                if (user.loginError()) return done(null, false, { error: user.loginError() });                
                return done(null, user);
            }
            done(null, false, { error: { message: "Invalid token.", code: "invalid_token" } });
        });
    }));

    passport.use(new LocalStrategy(function(username, password, done) {
        User.findOne({ name: username }, function(err, user) {
            if (err) return done(err, false);
            if (user) {
                if (user.loginError()) return done(null, false, { error: user.loginError() });
                return user.comparePassword(password, function(err, match) {
                    if (match && !err) return done(null, user);
                    done(null, false, { error: { message: "Incorrect username or password provided.", code: "invalid_credentials" } });
                });
            }
            done(null, false, { error: { message: "Incorrect username or password provided.", code: "invalid_credentials" } });
        });
    }));

    passport.serializeUser(function(user, done) {
        done(null, user.id);
    });

    passport.deserializeUser(function(user, done) {
        User.findById(user, (err, user) => done(err, user));
    });
}
{'fraction_non_alphanumeric': 0.14944939695857368, 'fraction_numerical': 0.0, 'mean_word_length': 2.4681818181818183, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5157328', 'n_tokens_mistral': 1087, 'n_tokens_neox': 1070, 'n_words': 249}