<commit_before>var express = require('express');
var router = express.Router();
var jwt = require('jsonwebtoken');

router.post('/login', function(req, res, next) {
  var username = req.body.username;
  var password = <PASSWORD>.body.password;
  var accessToken = req.get('X-Auth-Token');

  if (accessToken) {
    jwt.verify(accessToken, 'secretKey', function(err, decoded) {
      var existingUser = req.app.locals.users.findOne({'username': decoded.username});
      if (existingUser) {
        return res.json({
          user: existingUser,
          accessToken: jwt.sign({username: existingUser.username}, 'secretKey')
        });
      }
    });
  }

  var existingUser = req.app.locals.users.findOne({'username': username});
  if (existingUser && existingUser.password === password) {
    return res.json({
      user: existingUser,
      accessToken: jwt.sign({username: existingUser.username}, 'secretKey')
    });<commit_msg>fix(api): headers can not be set after they have been sent error<commit_after>var express = require('express');
var router = express.Router();
var jwt = require('jsonwebtoken');

router.post('/login', function(req, res, next) {
  var username = req.body.username;
  var password = <PASSWORD>;
  var accessToken = req.get('X-Auth-Token');

  if (accessToken) {
    jwt.verify(accessToken, 'secretKey', function(err, decoded) {
      if (!err) {
        var existingUser = req.app.locals.users.findOne({'username': decoded.username});
        if (existingUser) {
          return res.json({
            user: existingUser,
            accessToken: jwt.sign({username: existingUser.username}, 'secretKey')
          });
        }
      }
    });
  }

  if (username && password) {
    var existingUser = req.app.locals.users.findOne({'username': username});
    if (existingUser && existingUser.password === password) {
      return res.json({
        user: existingUser,
        accessToken: jwt.sign({username: existingUser.username}, 'secretKey')
      });
    }
{'fraction_non_alphanumeric': 0.15107553776888444, 'fraction_numerical': 0.0, 'mean_word_length': 3.25531914893617, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3469931', 'n_tokens_mistral': 595, 'n_tokens_neox': 586, 'n_words': 132}