From 4254ce9b2b1c6613b018bd32175466f3e4d2c56a Mon Sep 17 00:00:00 2001 From: Antoine Moreaux Date: Mon, 20 Jan 2025 17:39:12 +0100 Subject: [PATCH] fix(auth): improve query to find invitation (#9743) --- .../controllers/google-auth.controller.ts | 1 - .../controllers/microsoft-auth.controller.ts | 1 - .../auth/services/auth.service.ts | 26 +++++++------------ 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/packages/twenty-server/src/engine/core-modules/auth/controllers/google-auth.controller.ts b/packages/twenty-server/src/engine/core-modules/auth/controllers/google-auth.controller.ts index 644f857ab..7a4b9ba4f 100644 --- a/packages/twenty-server/src/engine/core-modules/auth/controllers/google-auth.controller.ts +++ b/packages/twenty-server/src/engine/core-modules/auth/controllers/google-auth.controller.ts @@ -70,7 +70,6 @@ export class GoogleAuthController { currentWorkspace && workspacePersonalInviteToken && email ? await this.authService.findInvitationForSignInUp({ currentWorkspace, - workspacePersonalInviteToken, email, }) : undefined; diff --git a/packages/twenty-server/src/engine/core-modules/auth/controllers/microsoft-auth.controller.ts b/packages/twenty-server/src/engine/core-modules/auth/controllers/microsoft-auth.controller.ts index 5e5a4e708..90c129540 100644 --- a/packages/twenty-server/src/engine/core-modules/auth/controllers/microsoft-auth.controller.ts +++ b/packages/twenty-server/src/engine/core-modules/auth/controllers/microsoft-auth.controller.ts @@ -68,7 +68,6 @@ export class MicrosoftAuthController { currentWorkspace && workspacePersonalInviteToken && email ? await this.authService.findInvitationForSignInUp({ currentWorkspace, - workspacePersonalInviteToken, email, }) : undefined; diff --git a/packages/twenty-server/src/engine/core-modules/auth/services/auth.service.ts b/packages/twenty-server/src/engine/core-modules/auth/services/auth.service.ts index 252fc04a2..6d8bc98ec 100644 --- a/packages/twenty-server/src/engine/core-modules/auth/services/auth.service.ts +++ b/packages/twenty-server/src/engine/core-modules/auth/services/auth.service.ts @@ -475,35 +475,29 @@ export class AuthService { return url.toString(); } - async findInvitationForSignInUp({ - currentWorkspace, - workspacePersonalInviteToken, - email, - }: { - currentWorkspace: Workspace | null; - workspacePersonalInviteToken?: string; - email?: string; - }) { - if (!currentWorkspace || !workspacePersonalInviteToken) return undefined; - + async findInvitationForSignInUp( + params: { + currentWorkspace: Workspace; + } & ({ workspacePersonalInviteToken: string } | { email: string }), + ) { const qr = this.appTokenRepository .createQueryBuilder('appToken') .where('"appToken"."workspaceId" = :workspaceId', { - workspaceId: currentWorkspace.id, + workspaceId: params.currentWorkspace.id, }) .andWhere('"appToken".type = :type', { type: AppTokenType.InvitationToken, }); - if (workspacePersonalInviteToken) { + if ('workspacePersonalInviteToken' in params) { qr.andWhere('"appToken".value = :personalInviteToken', { - personalInviteToken: workspacePersonalInviteToken, + personalInviteToken: params.workspacePersonalInviteToken, }); } - if (email) { + if ('email' in params) { qr.andWhere('"appToken".context->>\'email\' = :email', { - email, + email: params.email, }); }