diff --git a/apps/web/playwright/signup.e2e.ts b/apps/web/playwright/signup.e2e.ts index e6a731f638..896f976c64 100644 --- a/apps/web/playwright/signup.e2e.ts +++ b/apps/web/playwright/signup.e2e.ts @@ -2,6 +2,7 @@ import { expect } from "@playwright/test"; import { randomBytes } from "crypto"; import { IS_CALCOM } from "@calcom/lib/constants"; +import { prisma } from "@calcom/prisma"; import { test } from "./lib/fixtures"; diff --git a/packages/features/auth/signup/handlers/calcomHandler.ts b/packages/features/auth/signup/handlers/calcomHandler.ts index b7e88f8fd3..3eed36b1f3 100644 --- a/packages/features/auth/signup/handlers/calcomHandler.ts +++ b/packages/features/auth/signup/handlers/calcomHandler.ts @@ -52,7 +52,7 @@ async function handler(req: RequestWithUsernameStatus, res: NextApiResponse) { if (token) { foundToken = await findTokenByToken({ token }); throwIfTokenExpired(foundToken?.expires); - validateUsernameForTeam({ username, email, teamId: foundToken?.teamId }); + validateUsernameForTeam({ username, email, teamId: foundToken?.teamId ?? null }); } else { const usernameAndEmailValidation = await validateUsername(username, email); if (!usernameAndEmailValidation.isValid) { diff --git a/packages/features/auth/signup/utils/token.ts b/packages/features/auth/signup/utils/token.ts index bff5676a50..50991ca877 100644 --- a/packages/features/auth/signup/utils/token.ts +++ b/packages/features/auth/signup/utils/token.ts @@ -1,6 +1,7 @@ import dayjs from "@calcom/dayjs"; import { HttpError } from "@calcom/lib/http-error"; import { validateUsernameInTeam } from "@calcom/lib/validateUsername"; +import prisma from "@calcom/prisma"; export async function findTokenByToken({ token }: { token: string }) { const foundToken = await prisma.verificationToken.findFirst({ @@ -24,7 +25,8 @@ export async function findTokenByToken({ token }: { token: string }) { return foundToken; } -export function throwIfTokenExpired(expires: Date) { +export function throwIfTokenExpired(expires?: Date) { + if (!expires) return; if (dayjs(expires).isBefore(dayjs())) { throw new HttpError({ statusCode: 401,