fix(auth): improve query to find invitation (#9743)

This commit is contained in:
Antoine Moreaux
2025-01-20 17:39:12 +01:00
committed by GitHub
parent e0ea5b35d9
commit 4254ce9b2b
3 changed files with 10 additions and 18 deletions

View File

@ -70,7 +70,6 @@ export class GoogleAuthController {
currentWorkspace && workspacePersonalInviteToken && email currentWorkspace && workspacePersonalInviteToken && email
? await this.authService.findInvitationForSignInUp({ ? await this.authService.findInvitationForSignInUp({
currentWorkspace, currentWorkspace,
workspacePersonalInviteToken,
email, email,
}) })
: undefined; : undefined;

View File

@ -68,7 +68,6 @@ export class MicrosoftAuthController {
currentWorkspace && workspacePersonalInviteToken && email currentWorkspace && workspacePersonalInviteToken && email
? await this.authService.findInvitationForSignInUp({ ? await this.authService.findInvitationForSignInUp({
currentWorkspace, currentWorkspace,
workspacePersonalInviteToken,
email, email,
}) })
: undefined; : undefined;

View File

@ -475,35 +475,29 @@ export class AuthService {
return url.toString(); return url.toString();
} }
async findInvitationForSignInUp({ async findInvitationForSignInUp(
currentWorkspace, params: {
workspacePersonalInviteToken, currentWorkspace: Workspace;
email, } & ({ workspacePersonalInviteToken: string } | { email: string }),
}: { ) {
currentWorkspace: Workspace | null;
workspacePersonalInviteToken?: string;
email?: string;
}) {
if (!currentWorkspace || !workspacePersonalInviteToken) return undefined;
const qr = this.appTokenRepository const qr = this.appTokenRepository
.createQueryBuilder('appToken') .createQueryBuilder('appToken')
.where('"appToken"."workspaceId" = :workspaceId', { .where('"appToken"."workspaceId" = :workspaceId', {
workspaceId: currentWorkspace.id, workspaceId: params.currentWorkspace.id,
}) })
.andWhere('"appToken".type = :type', { .andWhere('"appToken".type = :type', {
type: AppTokenType.InvitationToken, type: AppTokenType.InvitationToken,
}); });
if (workspacePersonalInviteToken) { if ('workspacePersonalInviteToken' in params) {
qr.andWhere('"appToken".value = :personalInviteToken', { qr.andWhere('"appToken".value = :personalInviteToken', {
personalInviteToken: workspacePersonalInviteToken, personalInviteToken: params.workspacePersonalInviteToken,
}); });
} }
if (email) { if ('email' in params) {
qr.andWhere('"appToken".context->>\'email\' = :email', { qr.andWhere('"appToken".context->>\'email\' = :email', {
email, email: params.email,
}); });
} }