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 <me@alexvanandel.com>

* 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 <me@alexvanandel.com>
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
This commit is contained in:
Joe Au-Yeung
2025-06-11 22:21:58 +00:00
committed by GitHub
co-authored by Alex van Andel cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
parent 50c15f0d51
commit 86b1db57d5
2 changed files with 44 additions and 9 deletions
@@ -0,0 +1,33 @@
import prisma from "@calcom/prisma";
export class VerificationTokenRepository {
static async updateTeamInviteTokenExpirationDate({
email,
teamId,
expiresInDays,
}: {
email: string;
teamId: number;
expiresInDays: number;
}) {
const expires = new Date(Date.now() + expiresInDays * 24 * 60 * 60 * 1000);
const token = await prisma.verificationToken.findFirst({
where: {
identifier: email,
teamId,
},
});
await prisma.verificationToken.update({
where: {
identifier: email,
teamId,
token: token?.token,
},
data: { expires },
});
return { ...token, expires };
}
}
@@ -1,7 +1,7 @@
import { sendTeamInviteEmail } from "@calcom/emails";
import { WEBAPP_URL } from "@calcom/lib/constants";
import { getTranslation } from "@calcom/lib/server/i18n";
import { prisma } from "@calcom/prisma";
import { VerificationTokenRepository } from "@calcom/lib/server/repository/verificationToken";
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
import { ensureAtleastAdminPermissions, getTeamOrThrow } from "./inviteMember/utils";
@@ -24,15 +24,17 @@ export const resendInvitationHandler = async ({ ctx, input }: InviteMemberOption
isOrg: input.isOrg,
});
const verificationToken = await prisma.verificationToken.findFirst({
where: {
identifier: input.email,
let verificationToken;
try {
verificationToken = await VerificationTokenRepository.updateTeamInviteTokenExpirationDate({
email: input.email,
teamId: input.teamId,
},
select: {
token: true,
},
});
expiresInDays: 7,
});
} catch (error) {
console.error("[resendInvitationHandler] Error updating verification token: ", error);
}
const inviteTeamOptions = {
joinLink: `${WEBAPP_URL}/auth/login?callbackUrl=/settings/teams`,