fix borked e2e
parent
de12a7a11a
commit
b70838bed3
|
@ -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";
|
||||||
|
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
|
@ -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,
|
||||||
|
|
Loading…
Reference in New Issue