From ebec0f083f63f28295088df5fb7acf1dead7b493 Mon Sep 17 00:00:00 2001 From: Michael Bromley Date: Thu, 16 Jul 2020 13:09:23 +0200 Subject: [PATCH] fix(core): Fix bug where session user in cache would get removed --- .../core/src/service/services/session.service.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/core/src/service/services/session.service.ts b/packages/core/src/service/services/session.service.ts index 83ed554002..ee72aa3afc 100644 --- a/packages/core/src/service/services/session.service.ts +++ b/packages/core/src/service/services/session.service.ts @@ -167,7 +167,9 @@ export class SessionService implements EntitySubscriberInterface { } async setActiveOrder(serializedSession: CachedSession, order: Order): Promise { - const session = await this.connection.getRepository(Session).findOne(serializedSession.id); + const session = await this.connection + .getRepository(Session) + .findOne(serializedSession.id, { relations: ['user', 'user.roles', 'user.roles.channels'] }); if (session) { session.activeOrder = order; await this.connection.getRepository(Session).save(session, { reload: false }); @@ -182,10 +184,14 @@ export class SessionService implements EntitySubscriberInterface { if (serializedSession.activeOrderId) { const session = await this.connection .getRepository(Session) - .save({ id: serializedSession.id, activeOrder: null }); - const updatedSerializedSession = this.serializeSession(session); - await this.configService.authOptions.sessionCacheStrategy.set(updatedSerializedSession); - return updatedSerializedSession; + .findOne(serializedSession.id, { relations: ['user', 'user.roles', 'user.roles.channels'] }); + if (session) { + session.activeOrder = null; + await this.connection.getRepository(Session).save(session); + const updatedSerializedSession = this.serializeSession(session); + await this.configService.authOptions.sessionCacheStrategy.set(updatedSerializedSession); + return updatedSerializedSession; + } } return serializedSession; }