'use strict';

// const p = require('path');

const _ = require('lodash');
const passport = require('passport');

// const User = require('../services/users/model');

// const config = require(p.join(process.cwd(), 'server/config/membership'));

let serializeUser;
let deserializeUser;

// if (typeof config.serializeUser === 'function') {
//   if (config.serializeUser.length === 1) {
//     serializeUser = config.serializeUser(User);
//   } else {
//     serializeUser = config.serializeUser;
//   }
// }

// if (typeof config.deserializeUser === 'function') {
//   if (config.deserializeUser.length === 1) {
//     deserializeUser = config.deserializeUser(User);
//   } else {
//     deserializeUser = config.deserializeUser;
//   }
// }

// used to serialize the user for the session
passport.serializeUser(serializeUser || ((user, done) => {
  done(null, _.pick(user, ['id', 'username', 'email', 'roles']));
}));

// used to deserialize the user
passport.deserializeUser(deserializeUser || ((user, done) => {
  done(null, user);
  // User.findById(user, (err, user) => {
  //   done(err, user);
  // });
}));

require('./req');
require('./strategies');

@@ -8,19 +8,16 @@
 rict';%0A%0A
-// 
 const p 
@@ -153,27 +153,24 @@
 s/model');%0A%0A
-// 
 const config
@@ -274,16 +274,250 @@
 eUser;%0A%0A
+const pick = %5B'id', 'username', 'email', 'roles'%5D;%0A%0Aif (typeof config.serializeUser === 'function') %7B%0A  serializeUser = config.serializeUser;%0A%7D%0A%0Aif (Array.isArray(config.serializeColumns)) %7B%0A  pick.push(...config.serializeColumns);%0A%7D%0A
 // if (t
@@ -1099,44 +1099,12 @@
 er, 
-%5B'id', 'username', 'email', 'roles'%5D
+pick
 ));%0A
@@ -1228,83 +1228,8 @@
 r);%0A
-  // User.findById(user, (err, user) =%3E %7B%0A  //   done(err, user);%0A  // %7D);%0A
 %7D));

Enable passing custom columns to be serialized