diff --git a/api/src/app-modules/configureExpressSession.ts b/api/src/app-modules/configureExpressSession.ts index 7e8992a..67c5a22 100644 --- a/api/src/app-modules/configureExpressSession.ts +++ b/api/src/app-modules/configureExpressSession.ts @@ -1,10 +1,9 @@ -import { Express } from 'express' +import { Express, CookieOptions } from 'express' import mongoose from 'mongoose' import session from 'express-session' import MongoStore from 'connect-mongo' -import { ModeType } from '../utils' -import { cookieOptions } from '../app' +import { ModeType, ProtocolType } from '../utils' export const configureExpressSession = (app: Express) => { const { MODE } = process.env @@ -19,6 +18,15 @@ export const configureExpressSession = (app: Express) => { }) } + const { PROTOCOL } = process.env + const cookieOptions: CookieOptions = { + secure: PROTOCOL === ProtocolType.HTTPS, + httpOnly: true, + sameSite: PROTOCOL === ProtocolType.HTTPS ? 'none' : undefined, + maxAge: 24 * 60 * 60 * 1000, // 24 hours + domain: 'sas.4gl.io' + } + app.use( session({ secret: process.secrets.SESSION_SECRET, diff --git a/api/src/app.ts b/api/src/app.ts index 32a0634..9f51f0a 100644 --- a/api/src/app.ts +++ b/api/src/app.ts @@ -1,5 +1,5 @@ import path from 'path' -import express, { ErrorRequestHandler, CookieOptions } from 'express' +import express, { ErrorRequestHandler } from 'express' import cookieParser from 'cookie-parser' import dotenv from 'dotenv' @@ -8,7 +8,6 @@ import { getWebBuildFolder, instantiateLogger, loadAppStreamConfig, - ProtocolType, ReturnCode, setProcessVariables, setupFolders, @@ -30,15 +29,6 @@ if (verifyEnvVariables()) process.exit(ReturnCode.InvalidEnv) const app = express() -const { PROTOCOL } = process.env - -export const cookieOptions: CookieOptions = { - secure: PROTOCOL === ProtocolType.HTTPS, - httpOnly: true, - sameSite: PROTOCOL === ProtocolType.HTTPS ? 'none' : undefined, - maxAge: 24 * 60 * 60 * 1000 // 24 hours -} - const onError: ErrorRequestHandler = (err, req, res, next) => { console.error(err.stack) res.status(500).send('Something broke!')