From 3ce9e63410c78bcedbe32e26af8e5c8e3f08f906 Mon Sep 17 00:00:00 2001 From: Miodec Date: Mon, 3 Feb 2025 14:39:31 +0100 Subject: [PATCH] fix: email schema mismatch between frontend and backend --- frontend/src/ts/pages/login.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/frontend/src/ts/pages/login.ts b/frontend/src/ts/pages/login.ts index 51b574ece..3248406f8 100644 --- a/frontend/src/ts/pages/login.ts +++ b/frontend/src/ts/pages/login.ts @@ -6,6 +6,7 @@ import { InputIndicator } from "../elements/input-indicator"; import * as Skeleton from "../utils/skeleton"; import * as Misc from "../utils/misc"; import TypoList from "../utils/typo-list"; +import { z } from "zod"; export function enableSignUpButton(): void { $(".page.pageLogin .register.side button").prop("disabled", false); @@ -81,8 +82,6 @@ const checkNameDebounced = debounce(1000, async () => { const checkEmail = (): void => { const email = $(".page.pageLogin .register.side .emailInput").val() as string; - const emailRegex = - /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; const educationRegex = /@.*(student|education|school|\.edu$|\.edu\.|\.ac\.|\.sch\.)/i; @@ -90,7 +89,7 @@ const checkEmail = (): void => { return email.endsWith(typo); }); - if (emailRegex.test(email)) { + if (z.string().email().safeParse(email).success) { if (emailHasTypo) { emailIndicator.show( "typo", @@ -105,7 +104,7 @@ const checkEmail = (): void => { emailIndicator.show("valid"); } } else { - emailIndicator.show("invalid"); + emailIndicator.show("invalid", "Please enter a valid email address."); } updateSignupButton();