<commit_before>import { randomBytes } from 'crypto';
import { join } from 'path';
import { cpy, copy, appendFile, replaceCode, addNpmPackage } from '../utils';

async function generateCommonAuthenticationExpress(params) {
  const build = join(__base, 'build', params.uuid);
  const server = join(build, 'server.js');
  const env = join(build, '.env');
  const passportJs = join(build, 'config', 'passport.js');
  const passportConfigModule = join(__dirname, 'modules', 'common', 'passport-config.js');
  const passportConfigRequire = join(__dirname, 'modules', 'common', 'passport-config-require.js');
  const logoutRoute = join(__dirname, 'modules', 'common', 'logout-route.js');
  const unlinkRoute = join(__dirname, 'modules', 'common', 'unlink-route.js');
  const passportRequire = join(__dirname, 'modules', 'common', 'passport-require.js');
  const jwtRequire = join(__dirname, 'modules', 'common', 'jwt-require.js');
  const passportMiddleware = join(__dirname, 'modules', 'common', 'passport-middleware.js');
  const jwtIsAuthenticatedMiddleware = join(__dirname, 'modules', 'common', 'is-authenticated-jwt.js');
  const passportEnsureAuthenticated = join(__dirname, 'modules', 'common', 'ensure-authenticated-passport.js');
  const jwtEnsureAuthenticated = join(__dirname, 'modules', 'common', 'ensure-authenticated-jwt.js');
  const passportSerializer = join(__dirname, 'modules', 'common', 'passport-serializer.js');
  const passportDeserializerMongoDb = join(__dirname, 'modules', 'common', 'passport-deserializer.js');
  const passportDeserializerSql = join(__dirname, 'modules', 'common', 'passport-deserializer-sql.js');
  const userModelAppRequire = join(__dirname, 'modules', 'models', 'user-model-app-require.js');
  const userModelPassportRequire = join(__dirname, 'modules', 'models', 'user-model-passport-require.js');
  const userControllerModule = join(__dirname, 'modules', 'controllers', 'user.js');
  const userControllerRequire = join(__dirname, 'modules', 'controllers', 'user-require.js');
  const accountRoutesJwt = join(__dirname, 'modules', 'common', 'routes', 'account-routes-jwt.js');
  const accountRoutesPassport = join(__dirname, 'modules', 'common', 'routes', 'account-routes-passport.js');
  const generateTokenHelper = join(__dirname, 'modules', 'common', 'generate-token.js');

  const SQL = params.database === 'mysql' || params.database === 'postgresql' || params.database === 'sqlite';
  const MONGODB = params.database = 'mongodb';
  
  // Copy user controller
  await copy(userControllerModule, join(build, 'controllers', 'user.js'));

  const userController = join(build, 'controllers', 'user.js');

  if (params.jsFramework) {
    await replaceCode(server, 'IS_AUTHENTICATED_MIDDLEWARE', jwtIsAuthenticatedMiddleware);
    await replaceCode(server, 'JWT_REQUIRE', jwtRequire);
    await replaceCode(server, 'USER_MODEL_REQUIRE', userModelAppRequire);
    await replaceCode(userController, 'ENSURE_AUTHENTICATED_MIDDLEWARE', jwtEnsureAuthenticated);
    await replaceCode(userController, 'JWT_REQUIRE', jwtRequire);
    await replaceCode(userController, 'GENERATE_TOKEN', generateTokenHelper);
  } else {
    await replaceCode(userController, 'ENSURE_AUTHENTICATED_MIDDLEWARE', passportEnsureAuthenticated);
    await replaceCode(userController, 'PASSPORT_REQUIRE', passportRequire);
    await replaceCode(server, 'PASSPORT_REQUIRE', passportRequire);
    await replaceCode(server, 'PASSPORT_MIDDLEWARE', passportMiddleware);
    await replaceCode(server, 'PASSPORT_CONFIG_REQUIRE', passportConfigRequire);
  }

  // Add user controller reference
  await replaceCode(server, 'USER_CONTROLLER', userControllerRequire);


  if (params.jsFramework) {
    await replaceCode(server, 'UNLINK_ROUTE', unlinkRoute);
    await replaceCode(server, 'ACCOUNT_ROUTES', accountRoutesJwt);

    await addNpmPackage('jsonwebtoken', params);<commit_msg>Fixed accidental database param override<commit_after>import { randomBytes } from 'crypto';
import { join } from 'path';
import { cpy, copy, appendFile, replaceCode, addNpmPackage } from '../utils';

async function generateCommonAuthenticationExpress(params) {
  const build = join(__base, 'build', params.uuid);
  const server = join(build, 'server.js');
  const env = join(build, '.env');
  const passportJs = join(build, 'config', 'passport.js');
  const passportConfigModule = join(__dirname, 'modules', 'common', 'passport-config.js');
  const passportConfigRequire = join(__dirname, 'modules', 'common', 'passport-config-require.js');
  const logoutRoute = join(__dirname, 'modules', 'common', 'logout-route.js');
  const unlinkRoute = join(__dirname, 'modules', 'common', 'unlink-route.js');
  const passportRequire = join(__dirname, 'modules', 'common', 'passport-require.js');
  const jwtRequire = join(__dirname, 'modules', 'common', 'jwt-require.js');
  const passportMiddleware = join(__dirname, 'modules', 'common', 'passport-middleware.js');
  const jwtIsAuthenticatedMiddleware = join(__dirname, 'modules', 'common', 'is-authenticated-jwt.js');
  const passportEnsureAuthenticated = join(__dirname, 'modules', 'common', 'ensure-authenticated-passport.js');
  const jwtEnsureAuthenticated = join(__dirname, 'modules', 'common', 'ensure-authenticated-jwt.js');
  const passportSerializer = join(__dirname, 'modules', 'common', 'passport-serializer.js');
  const passportDeserializerMongoDb = join(__dirname, 'modules', 'common', 'passport-deserializer.js');
  const passportDeserializerSql = join(__dirname, 'modules', 'common', 'passport-deserializer-sql.js');
  const userModelAppRequire = join(__dirname, 'modules', 'models', 'user-model-app-require.js');
  const userModelPassportRequire = join(__dirname, 'modules', 'models', 'user-model-passport-require.js');
  const userControllerModule = join(__dirname, 'modules', 'controllers', 'user.js');
  const userControllerRequire = join(__dirname, 'modules', 'controllers', 'user-require.js');
  const accountRoutesJwt = join(__dirname, 'modules', 'common', 'routes', 'account-routes-jwt.js');
  const accountRoutesPassport = join(__dirname, 'modules', 'common', 'routes', 'account-routes-passport.js');
  const generateTokenHelper = join(__dirname, 'modules', 'common', 'generate-token.js');

  // Copy user controller
  await copy(userControllerModule, join(build, 'controllers', 'user.js'));

  const userController = join(build, 'controllers', 'user.js');

  if (params.jsFramework) {
    await replaceCode(server, 'IS_AUTHENTICATED_MIDDLEWARE', jwtIsAuthenticatedMiddleware);
    await replaceCode(server, 'JWT_REQUIRE', jwtRequire);
    await replaceCode(server, 'USER_MODEL_REQUIRE', userModelAppRequire);
    await replaceCode(userController, 'ENSURE_AUTHENTICATED_MIDDLEWARE', jwtEnsureAuthenticated);
    await replaceCode(userController, 'JWT_REQUIRE', jwtRequire);
    await replaceCode(userController, 'GENERATE_TOKEN', generateTokenHelper);
  } else {
    await replaceCode(userController, 'ENSURE_AUTHENTICATED_MIDDLEWARE', passportEnsureAuthenticated);
    await replaceCode(userController, 'PASSPORT_REQUIRE', passportRequire);
    await replaceCode(server, 'PASSPORT_REQUIRE', passportRequire);
    await replaceCode(server, 'PASSPORT_MIDDLEWARE', passportMiddleware);
    await replaceCode(server, 'PASSPORT_CONFIG_REQUIRE', passportConfigRequire);
  }

  // Add user controller reference
  await replaceCode(server, 'USER_CONTROLLER', userControllerRequire);


  if (params.jsFramework) {
    await replaceCode(server, 'UNLINK_ROUTE', unlinkRoute);
    await replaceCode(server, 'ACCOUNT_ROUTES', accountRoutesJwt);

    await addNpmPackage('jsonwebtoken', params);
{'fraction_non_alphanumeric': 0.14098532494758909, 'fraction_numerical': 0.0, 'mean_word_length': 6.772912423625255, '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': '5034640', 'n_tokens_mistral': 2280, 'n_tokens_neox': 2317, 'n_words': 495}