Skip to content

Commit 86b1db5

Browse files
joeauyeungemrysalcubic-dev-ai[bot]
authored
fix: Resending team invites now updates token expiry date (#21774)
* Create `VerificationTokenRepository` * Update the verification token expiry when resending the invite * Handle error * Fix import * Get past unique constraint * Update packages/trpc/server/routers/viewer/teams/resendInvitation.handler.ts Co-authored-by: Alex van Andel <[email protected]> * Update packages/lib/server/repository/verificationToken.ts Update set expiry time Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> * Type fix * Update how we're fetching the token --------- Co-authored-by: Alex van Andel <[email protected]> Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
1 parent 50c15f0 commit 86b1db5

File tree

2 files changed

+44
-9
lines changed

2 files changed

+44
-9
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import prisma from "@calcom/prisma";
2+
3+
export class VerificationTokenRepository {
4+
static async updateTeamInviteTokenExpirationDate({
5+
email,
6+
teamId,
7+
expiresInDays,
8+
}: {
9+
email: string;
10+
teamId: number;
11+
expiresInDays: number;
12+
}) {
13+
const expires = new Date(Date.now() + expiresInDays * 24 * 60 * 60 * 1000);
14+
15+
const token = await prisma.verificationToken.findFirst({
16+
where: {
17+
identifier: email,
18+
teamId,
19+
},
20+
});
21+
22+
await prisma.verificationToken.update({
23+
where: {
24+
identifier: email,
25+
teamId,
26+
token: token?.token,
27+
},
28+
data: { expires },
29+
});
30+
31+
return { ...token, expires };
32+
}
33+
}

packages/trpc/server/routers/viewer/teams/resendInvitation.handler.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { sendTeamInviteEmail } from "@calcom/emails";
22
import { WEBAPP_URL } from "@calcom/lib/constants";
33
import { getTranslation } from "@calcom/lib/server/i18n";
4-
import { prisma } from "@calcom/prisma";
4+
import { VerificationTokenRepository } from "@calcom/lib/server/repository/verificationToken";
55
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
66

77
import { ensureAtleastAdminPermissions, getTeamOrThrow } from "./inviteMember/utils";
@@ -24,15 +24,17 @@ export const resendInvitationHandler = async ({ ctx, input }: InviteMemberOption
2424
isOrg: input.isOrg,
2525
});
2626

27-
const verificationToken = await prisma.verificationToken.findFirst({
28-
where: {
29-
identifier: input.email,
27+
let verificationToken;
28+
29+
try {
30+
verificationToken = await VerificationTokenRepository.updateTeamInviteTokenExpirationDate({
31+
email: input.email,
3032
teamId: input.teamId,
31-
},
32-
select: {
33-
token: true,
34-
},
35-
});
33+
expiresInDays: 7,
34+
});
35+
} catch (error) {
36+
console.error("[resendInvitationHandler] Error updating verification token: ", error);
37+
}
3638

3739
const inviteTeamOptions = {
3840
joinLink: `${WEBAPP_URL}/auth/login?callbackUrl=/settings/teams`,

0 commit comments

Comments
 (0)