From b70838bed36fbe3e1cf0da35299b382a34745e15 Mon Sep 17 00:00:00 2001 From: Sean Brydon Date: Mon, 16 Oct 2023 14:49:01 +0100 Subject: [PATCH] fix borked e2e --- apps/web/playwright/signup.e2e.ts | 1 + packages/features/auth/signup/handlers/calcomHandler.ts | 2 +- packages/features/auth/signup/utils/token.ts | 4 +++- 3 files changed, 5 insertions(+), 2 deletions(-) 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,