<commit_before>'use strict';

let jwt = require('jsonwebtoken');
let User = require('../user/model');

function authenticate(req, res) {
  let body = {
    bnetId: req.user.id,
    battletag: req.user.battletag,
    token: req.user.token,
    provider: req.user.provider
  };

  User
   .findOneAndUpdate(
     {bnetId: req.user.id, battletag: req.user.battletag},
     body,
     {upsert: true}
   )
   .exec()
   .then(() => {
     let token = jwt.sign({
       bnetId: req.user.id,
       battletag: req.user.battletag
     }, req.app.get('superSecret'), {
       // expiresInMinutes: 1440 // expires in 24 hours
     });

     res.cookie('token', token, {
       domain: (app.get('env') === 'local') ? 'localhost' : '.nobreaksguild.com',
       secure: true
     });
     res.redirect(req.headers.referer || '/');
   });
}

function logout(req, res) {
  req.logout();
  res.cookie('token', '', { expires: new Date() });
  res.redirect(req.headers.referer);
}

module.exports = {
  authenticate: authenticate,
  logout: logout
};<commit_msg>Fix cookies again<commit_after>'use strict';

let jwt = require('jsonwebtoken');
let User = require('../user/model');

function authenticate(req, res) {
  let body = {
    bnetId: req.user.id,
    battletag: req.user.battletag,
    token: req.user.token,
    provider: req.user.provider
  };

  User
   .findOneAndUpdate(
     {bnetId: req.user.id, battletag: req.user.battletag},
     body,
     {upsert: true}
   )
   .exec()
   .then(() => {
     let token = jwt.sign({
       bnetId: req.user.id,
       battletag: req.user.battletag
     }, req.app.get('superSecret'), {
       // expiresInMinutes: 1440 // expires in 24 hours
     });

     res.cookie('token', token, {
       domain: (req.app.get('env') === 'local') ? 'localhost' : '.nobreaksguild.com',
       secure: true
     });
     res.redirect(req.headers.referer || '/');
   });
}

function logout(req, res) {
  req.logout();
  res.cookie('token', '', { expires: new Date() });
  res.redirect(req.headers.referer);
}

module.exports = {
  authenticate: authenticate,
  logout: logout
};
{'fraction_non_alphanumeric': 0.17891221374045801, 'fraction_numerical': 0.0057251908396946565, 'mean_word_length': 2.744642857142857, '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': '79065', 'n_tokens_mistral': 775, 'n_tokens_neox': 758, 'n_words': 142}