diff --git a/ExpressAPI/src/controllers/Session.ts b/ExpressAPI/src/controllers/Session.ts index cb157695fed0d55fb83bd1af9ebd89564fb7ef5a..3baf624bf8aa066280fa1dd92cf28691c70db2a5 100644 --- a/ExpressAPI/src/controllers/Session.ts +++ b/ExpressAPI/src/controllers/Session.ts @@ -5,6 +5,7 @@ import Config from '../config/Config'; import express from 'express'; import ApiRequest from '../models/ApiRequest'; import User from '../models/User'; +import UserManager from '../managers/UserManager'; class Session { @@ -19,16 +20,19 @@ class Session { this._profile = newProfile; } - constructor(req: ApiRequest) { + constructor() { } + + async initSession(req: ApiRequest) { const authorization = req.headers.authorization; if ( authorization ) { const jwtToken = authorization.replace('Bearer ', ''); try { - const jwtData = jwt.verify(jwtToken, Config.jwtSecretKey) as JwtPayload; + const jwtData = jwt.verify(jwtToken, Config.jwtConfig.secret) as JwtPayload; if ( jwtData.profile ) { this.profile.importFromJsonObject(jwtData.profile); + this.profile = await UserManager.getById(this.profile.userID); this.profile.currentSession = this; } } catch ( err ) { } diff --git a/ExpressAPI/src/middlewares/SessionMiddleware.ts b/ExpressAPI/src/middlewares/SessionMiddleware.ts index 49fd6114a783c06f32242c3594bbb6ded5f12fb8..664edcba6182c7c3452b851c26b20cafd100b495 100644 --- a/ExpressAPI/src/middlewares/SessionMiddleware.ts +++ b/ExpressAPI/src/middlewares/SessionMiddleware.ts @@ -18,7 +18,8 @@ class SessionMiddleware { register(): (req: ApiRequest, res: express.Response, next: express.NextFunction) => void { return async (req: ApiRequest, res: express.Response, next: express.NextFunction) => { - req.session = new Session(req); + req.session = new Session(); + await req.session.initSession(req); return next(); };