diff --git a/packages/twenty-server/src/engine/core-modules/auth/strategies/jwt.auth.strategy.spec.ts b/packages/twenty-server/src/engine/core-modules/auth/strategies/jwt.auth.strategy.spec.ts index 192fbe176..345b6d946 100644 --- a/packages/twenty-server/src/engine/core-modules/auth/strategies/jwt.auth.strategy.spec.ts +++ b/packages/twenty-server/src/engine/core-modules/auth/strategies/jwt.auth.strategy.spec.ts @@ -208,10 +208,11 @@ describe('JwtAuthStrategy', () => { } }); - it('should be truthy if type is ACCESS, no jti, and user and userWorkspace exist', async () => { + it('should not throw if type is ACCESS, no jti, and user and userWorkspace exist', async () => { const payload = { sub: 'sub-default', type: 'ACCESS', + userWorkspaceId: 'userWorkspaceId', }; workspaceRepository = { diff --git a/packages/twenty-server/src/engine/core-modules/auth/strategies/jwt.auth.strategy.ts b/packages/twenty-server/src/engine/core-modules/auth/strategies/jwt.auth.strategy.ts index d72cadb88..780a43775 100644 --- a/packages/twenty-server/src/engine/core-modules/auth/strategies/jwt.auth.strategy.ts +++ b/packages/twenty-server/src/engine/core-modules/auth/strategies/jwt.auth.strategy.ts @@ -120,6 +120,13 @@ export class JwtAuthStrategy extends PassportStrategy(Strategy, 'jwt') { ); } + if (!payload.userWorkspaceId) { + throw new AuthException( + 'UserWorkspace not found', + AuthExceptionCode.USER_WORKSPACE_NOT_FOUND, + ); + } + const userWorkspace = await this.userWorkspaceRepository.findOne({ where: { id: payload.userWorkspaceId,