fix(auth): improve query to find invitation (#9743)
This commit is contained in:
@ -70,7 +70,6 @@ export class GoogleAuthController {
|
||||
currentWorkspace && workspacePersonalInviteToken && email
|
||||
? await this.authService.findInvitationForSignInUp({
|
||||
currentWorkspace,
|
||||
workspacePersonalInviteToken,
|
||||
email,
|
||||
})
|
||||
: undefined;
|
||||
|
||||
@ -68,7 +68,6 @@ export class MicrosoftAuthController {
|
||||
currentWorkspace && workspacePersonalInviteToken && email
|
||||
? await this.authService.findInvitationForSignInUp({
|
||||
currentWorkspace,
|
||||
workspacePersonalInviteToken,
|
||||
email,
|
||||
})
|
||||
: undefined;
|
||||
|
||||
@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user