diff --git a/ExpressAPI/src/config/Config.ts b/ExpressAPI/src/config/Config.ts index 8969008c9980168af765554c7ed0f356621ef0bd..eee304c8208c2efc0883fd966e4b540e3b14d919 100644 --- a/ExpressAPI/src/config/Config.ts +++ b/ExpressAPI/src/config/Config.ts @@ -9,8 +9,9 @@ class Config { type: string, host: string, port: number, user: string, password: string, database: string }; - public readonly jwtSecretKey: string; - public readonly sessionTimeout: number; + public jwtConfig: { + secret: string; expiresIn: number; + }; public permissions: { teachingStaff: Array<string>; @@ -33,8 +34,10 @@ class Config { database: process.env.DATABASE_NAME }; - this.jwtSecretKey = process.env.JWT_SECRET_KEY; - this.sessionTimeout = Number(process.env.SESSION_TIMEOUT); + this.jwtConfig = { + secret : process.env.JWT_SECRET_KEY, + expiresIn: Number(process.env.SESSION_TIMEOUT) + }; this.permissions = { teachingStaff: JSON.parse(process.env.ROLES_WITH_TEACHING_STAFF_PERMISSIONS) diff --git a/ExpressAPI/src/controllers/Session.ts b/ExpressAPI/src/controllers/Session.ts index 3baf624bf8aa066280fa1dd92cf28691c70db2a5..fdbd80032cf4751e4ba9f3204f027986b7377e90 100644 --- a/ExpressAPI/src/controllers/Session.ts +++ b/ExpressAPI/src/controllers/Session.ts @@ -40,7 +40,7 @@ class Session { } private static getToken(profileJson: any): string { - return profileJson.id === null ? null : jwt.sign({ profile: profileJson }, Config.jwtSecretKey, { expiresIn: Config.sessionTimeout }); + return profileJson.id === null ? null : jwt.sign({ profile: profileJson }, Config.jwtConfig.secret, Config.jwtConfig.expiresIn > 0 ? { expiresIn: Config.jwtConfig.expiresIn } : {}); } private async getResponse(code: number, data: any, descriptionOverride?: string): Promise<any> {