fix borked e2e

pull/11421/merge^2
Sean Brydon 2023-10-16 14:49:01 +01:00
parent de12a7a11a
commit b70838bed3
3 changed files with 5 additions and 2 deletions

View File

@ -2,6 +2,7 @@ import { expect } from "@playwright/test";
import { randomBytes } from "crypto"; import { randomBytes } from "crypto";
import { IS_CALCOM } from "@calcom/lib/constants"; import { IS_CALCOM } from "@calcom/lib/constants";
import { prisma } from "@calcom/prisma";
import { test } from "./lib/fixtures"; import { test } from "./lib/fixtures";

View File

@ -52,7 +52,7 @@ async function handler(req: RequestWithUsernameStatus, res: NextApiResponse) {
if (token) { if (token) {
foundToken = await findTokenByToken({ token }); foundToken = await findTokenByToken({ token });
throwIfTokenExpired(foundToken?.expires); throwIfTokenExpired(foundToken?.expires);
validateUsernameForTeam({ username, email, teamId: foundToken?.teamId }); validateUsernameForTeam({ username, email, teamId: foundToken?.teamId ?? null });
} else { } else {
const usernameAndEmailValidation = await validateUsername(username, email); const usernameAndEmailValidation = await validateUsername(username, email);
if (!usernameAndEmailValidation.isValid) { if (!usernameAndEmailValidation.isValid) {

View File

@ -1,6 +1,7 @@
import dayjs from "@calcom/dayjs"; import dayjs from "@calcom/dayjs";
import { HttpError } from "@calcom/lib/http-error"; import { HttpError } from "@calcom/lib/http-error";
import { validateUsernameInTeam } from "@calcom/lib/validateUsername"; import { validateUsernameInTeam } from "@calcom/lib/validateUsername";
import prisma from "@calcom/prisma";
export async function findTokenByToken({ token }: { token: string }) { export async function findTokenByToken({ token }: { token: string }) {
const foundToken = await prisma.verificationToken.findFirst({ const foundToken = await prisma.verificationToken.findFirst({
@ -24,7 +25,8 @@ export async function findTokenByToken({ token }: { token: string }) {
return foundToken; return foundToken;
} }
export function throwIfTokenExpired(expires: Date) { export function throwIfTokenExpired(expires?: Date) {
if (!expires) return;
if (dayjs(expires).isBefore(dayjs())) { if (dayjs(expires).isBefore(dayjs())) {
throw new HttpError({ throw new HttpError({
statusCode: 401, statusCode: 401,