<commit_before>require('dotenv').config();

const bodyParser = require('body-parser');
const express = require('express');
const LocalStrategy = require('passport-local').Strategy;
const passport = require('passport');
const path = require('path');
const session = require('express-session');

const mongoose = require('./server/mongoose');

const config = require('./server/_config.js');
const ErrorHandler = require('./server/controllers/ErrorHandler.js');
const User = mongoose.model('User');

// ===== App Setup =====
const app = express();

app.use(bodyParser.json());

app.use(express.static(path.join(__dirname, 'client', 'build')));

app.use(
  session({
    secret: 'supersecret',
    resave: true,
    saveUninitialized: true,
  })
);

app.use(passport.initialize());
app.use(passport.session());
passport.use(User.createStrategy());

passport.serializeUser(User.serializeUser());
passport.deserializeUser(User.deserializeUser());

// ===== Routes =====
const authController = require('./server/controllers/authController');
const userController = require('./server/controllers/userController');
const jobRoutes = require('./server/routes/jobs');

// ===== Server Setup =====
const PORT = process.env.PORT || 3001;

// ===== App Use Routes =====
app.use('/api/v1', jobRoutes);

app.get('/test-login/', authController.isLoggedIn, (req, res) => {
  res.send(`Logged in as ${req.user.username}`);
});

app.post(
  '/register/',
  userController.register,
  authController.login,
  (req, res) => {
    res.json({ loggedIn: true });
  }
);

app.post('/login/', authController.login, (req, res) => {
  res.send({ loggedIn: true });
});

app.get('/logout/', authController.logout);

app.get('*', (req, res) => {
  res.sendFile(path.join(__dirname, 'client', 'build', 'index.html'));
});

// ====== Error Handler Middleware =====
app.use(ErrorHandler);

app.listen(PORT, () => {
  console.log('API listening on port ' + PORT);
});

module.exports = app;<commit_msg>Add isAdmin to login reponse JSON<commit_after>require('dotenv').config();

const bodyParser = require('body-parser');
const express = require('express');
const LocalStrategy = require('passport-local').Strategy;
const passport = require('passport');
const path = require('path');
const session = require('express-session');

const mongoose = require('./server/mongoose');

const config = require('./server/_config.js');
const ErrorHandler = require('./server/controllers/ErrorHandler.js');
const User = mongoose.model('User');

// ===== App Setup =====
const app = express();

app.use(bodyParser.json());

app.use(express.static(path.join(__dirname, 'client', 'build')));

app.use(
  session({
    secret: 'supersecret',
    resave: true,
    saveUninitialized: true,
  })
);

app.use(passport.initialize());
app.use(passport.session());
passport.use(User.createStrategy());

passport.serializeUser(User.serializeUser());
passport.deserializeUser(User.deserializeUser());

// ===== Routes =====
const authController = require('./server/controllers/authController');
const userController = require('./server/controllers/userController');
const jobRoutes = require('./server/routes/jobs');

// ===== Server Setup =====
const PORT = process.env.PORT || 3001;

// ===== App Use Routes =====
app.use('/api/v1', jobRoutes);

app.get('/test-login/', authController.isLoggedIn, (req, res) => {
  res.send(`Logged in as ${req.user.username}`);
});

app.post(
  '/register/',
  userController.register,
  authController.login,
  (req, res) => {
    res.json({ loggedIn: true });
  }
);

app.post('/login/', authController.login, (req, res) => {
  res.send({
    loggedIn: true,
    isAdmin: req.user.isAdmin,
  });
});

app.get('/logout/', authController.logout);

app.get('*', (req, res) => {
  res.sendFile(path.join(__dirname, 'client', 'build', 'index.html'));
});

// ====== Error Handler Middleware =====
app.use(ErrorHandler);

app.listen(PORT, () => {
  console.log('API listening on port ' + PORT);
});

module.exports = app;
{'fraction_non_alphanumeric': 0.2121743486973948, 'fraction_numerical': 0.00250501002004008, 'mean_word_length': 4.995495495495495, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '5772312', 'n_tokens_mistral': 1271, 'n_tokens_neox': 1272, 'n_words': 244}