Skip to content

Commit 3ce9e63

Browse files
committed
fix: email schema mismatch between frontend and backend
1 parent 0b3f5aa commit 3ce9e63

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

frontend/src/ts/pages/login.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { InputIndicator } from "../elements/input-indicator";
66
import * as Skeleton from "../utils/skeleton";
77
import * as Misc from "../utils/misc";
88
import TypoList from "../utils/typo-list";
9+
import { z } from "zod";
910

1011
export function enableSignUpButton(): void {
1112
$(".page.pageLogin .register.side button").prop("disabled", false);
@@ -81,16 +82,14 @@ const checkNameDebounced = debounce(1000, async () => {
8182

8283
const checkEmail = (): void => {
8384
const email = $(".page.pageLogin .register.side .emailInput").val() as string;
84-
const emailRegex =
85-
/^(([^<>()[\]\\.,;:\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,}))$/;
8685
const educationRegex =
8786
/@.*(student|education|school|\.edu$|\.edu\.|\.ac\.|\.sch\.)/i;
8887

8988
const emailHasTypo = TypoList.some((typo) => {
9089
return email.endsWith(typo);
9190
});
9291

93-
if (emailRegex.test(email)) {
92+
if (z.string().email().safeParse(email).success) {
9493
if (emailHasTypo) {
9594
emailIndicator.show(
9695
"typo",
@@ -105,7 +104,7 @@ const checkEmail = (): void => {
105104
emailIndicator.show("valid");
106105
}
107106
} else {
108-
emailIndicator.show("invalid");
107+
emailIndicator.show("invalid", "Please enter a valid email address.");
109108
}
110109

111110
updateSignupButton();

0 commit comments

Comments
 (0)