<commit_before>var TwitterStrategy = require('passport-twitter').Strategy;
var User = require('../models/user');

var configAuth = require('./auth');

module.exports = function(passport) {
  passport.serializeUser(serialize);
  passport.deserializeUser(deserialize);
  passport.use(new TwitterStrategy({
    consumerSecret: configAuth.twitterAuth.consumerSecret,
    consumerKey: configAuth.twitterAuth.consumerKey,
    callbackURL: configAuth.twitterAuth.callbackURL
  }, twitterAuth));
}

function serialize(user, done) {
  done(null, user._id);
}

function deserialize(id, done) {
  User.findById(id, function(err, user) {
    if (err)
      done(err, null);
    done(err, user);
  });
}

function twitterAuth(token, tokenSecret, profile, done) {
  process.nextTick(function() {
    User.findOne({ 'twitter.id': profile.id }, function(err, user) {
      if (err)
        return done(err);

      if (user) {
        return done(null, user);
      } else {
        var newUser = new User();
        newUser.twitter.id = profile.id;
        newUser.twitter.token = token;
        newUser.twitter.tokenSecret = tokenSecret;
        newUser.twitter.username = profile.username;
        newUser.twitter.displayName = profile.displayName;

        newUser.save(function(err) {
          if (err)
            throw err;

          return done(null, newUser);
        });
      }
    });
  });
}
<commit_msg>Adds changes to deserialize function of passport.js<commit_after>var TwitterStrategy = require('passport-twitter').Strategy;
var User = require('../models/user');

var configAuth = require('./auth');

module.exports = function(passport) {
  passport.serializeUser(serialize);
  passport.deserializeUser(deserialize);
  passport.use(new TwitterStrategy({
    consumerSecret: configAuth.twitterAuth.consumerSecret,
    consumerKey: configAuth.twitterAuth.consumerKey,
    callbackURL: configAuth.twitterAuth.callbackURL
  }, twitterAuth));
}

function serialize(user, done) {
  done(null, user._id);
}

function deserialize(id, done) {
  User.findById(id, function(err, user) {
    if (err)
      done(err, null);
      
    done(err, user);
  });
}

function twitterAuth(token, tokenSecret, profile, done) {
  process.nextTick(function() {
    User.findOne({ 'twitter.id': profile.id }, function(err, user) {
      if (err)
        return done(err);

      if (user) {
        return done(null, user);
      } else {
        var newUser = new User();
        newUser.twitter.id = profile.id;
        newUser.twitter.token = token;
        newUser.twitter.tokenSecret = tokenSecret;
        newUser.twitter.username = profile.username;
        newUser.twitter.displayName = profile.displayName;

        newUser.save(function(err) {
          if (err)
            throw err;

          return done(null, newUser);
        });
      }
    });
  });
}

{'fraction_non_alphanumeric': 0.13153279551034724, 'fraction_numerical': 0.0, 'mean_word_length': 3.011251758087201, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2179038', 'n_tokens_mistral': 860, 'n_tokens_neox': 848, 'n_words': 170}