<commit_before>import passport from 'passport';

function configureApp(app, loginRoute, logoutRoute, userDetailsExtractor, loadInitialData) {
  app.use(passport.initialize());
  app.use(passport.session());

  app.post(loginRoute, (req, res, next) => {
    passport.authenticate('local', (err, user, params) => {
      if (err) return next(err);
      if (!user) return res.status(401).json({error: params ? params.message : 'Invalid login'});
        req.login(user, {}, error => {
        if (error) return res.status(500).json({error});
        const initialData = loadInitialData(user);
        return res.json({
          ...initialData,
          user: userDetailsExtractor(user),
          returnTo: (req.session && req.session.returnTo) ? req.session.returnTo : '/'
        });
      });
    })(req, res, next);
  });

  app.get(logoutRoute, (req, res) => {
    req.logout();
    res.end();
  })
}

export default configureApp;<commit_msg>loadInitialData expects promise returned also pass in req<commit_after>import passport from 'passport';

function configureApp(app, loginRoute, logoutRoute, userDetailsExtractor, loadInitialData) {
  app.use(passport.initialize());
  app.use(passport.session());

  app.post(loginRoute, (req, res, next) => {
    passport.authenticate('local', (err, user, params) => {
      if (err) return next(err);
      if (!user) return res.status(401).json({error: params ? params.message : 'Invalid login'});
        req.login(user, {}, error => {
        if (error) return res.status(500).json({error});
        loadInitialData(user, req).then(initialData => {
          res.json({
            ...initialData,
            user: userDetailsExtractor(user),
            returnTo: (req.session && req.session.returnTo) ? req.session.returnTo : '/'
          });
        });
      });
    })(req, res, next);
  });

  app.get(logoutRoute, (req, res) => {
    req.logout();
    res.end();
  })
}

export default configureApp;
{'fraction_non_alphanumeric': 0.16590096988259315, 'fraction_numerical': 0.006125574272588055, 'mean_word_length': 3.0748440748440746, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, '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': '1746905', 'n_tokens_mistral': 614, 'n_tokens_neox': 594, 'n_words': 126}