diff --git a/apps/edr-freight-web/portal/src/pages/accounts/SetPasswordPage.tsx b/apps/edr-freight-web/portal/src/pages/accounts/SetPasswordPage.tsx index ee8dd1922..04625f2cd 100644 --- a/apps/edr-freight-web/portal/src/pages/accounts/SetPasswordPage.tsx +++ b/apps/edr-freight-web/portal/src/pages/accounts/SetPasswordPage.tsx @@ -1,4 +1,13 @@ -import { Alert, Box, Button, Group, PasswordInput, Stack, Text, ThemeIcon } from "@mantine/core"; +import { + Alert, + Box, + Button, + Group, + PasswordInput, + Stack, + Text, + ThemeIcon, +} from "@mantine/core"; import { zodResolver } from "@hookform/resolvers/zod"; import { ArrowRight, Check, LockKeyhole, X } from "lucide-react"; import { useMemo, useState } from "react"; @@ -9,7 +18,6 @@ import { z } from "zod"; import useAuth from "@/hooks/useAuth"; import AuthLayout from "@/components/auth/AuthLayout"; import { - PASSWORD_MISMATCH, confirmPasswordField, passwordField, passwordRequirements, @@ -21,7 +29,10 @@ const passwordSchema = z password: passwordField, confirmPassword: confirmPasswordField, }) - .refine(samePassword, PASSWORD_MISMATCH); + .refine(samePassword, { + message: "Passwords do not match", + path: ["confirmPassword"], + }); type FormData = z.infer; @@ -44,7 +55,8 @@ export default function SetPasswordPage() { const password = watch("password"); const requirements = useMemo( - () => passwordRequirements.map((r) => ({ ...r, met: r.test(password || "") })), + () => + passwordRequirements.map((r) => ({ ...r, met: r.test(password || "") })), [password], ); @@ -83,11 +95,21 @@ export default function SetPasswordPage() { "Secure freight operations", "Advanced authentication system", ], - stats: { label: "Security Protection", value: "256-bit", footer: "Encrypted", progress: "w-[98%]" }, + stats: { + label: "Security Protection", + value: "256-bit", + footer: "Encrypted", + progress: "w-[98%]", + }, }} > - + diff --git a/apps/edr-freight-web/portal/src/pages/accounts/SignupPage.tsx b/apps/edr-freight-web/portal/src/pages/accounts/SignupPage.tsx index fe2fb09cd..72dafe9f7 100644 --- a/apps/edr-freight-web/portal/src/pages/accounts/SignupPage.tsx +++ b/apps/edr-freight-web/portal/src/pages/accounts/SignupPage.tsx @@ -27,7 +27,6 @@ import PasswordChecklist from "@/components/auth/PasswordChecklist"; import { ControlledPhoneField, isValidPhone } from "@/components/PhoneField"; import { api } from "@/services/api"; import { - PASSWORD_MISMATCH, confirmPasswordField, passwordField, samePassword, @@ -53,7 +52,10 @@ const userSchema = z password: passwordField, confirmPassword: confirmPasswordField, }) - .refine(samePassword, PASSWORD_MISMATCH); + .refine(samePassword, { + message: "Passwords do not match", + path: ["confirmPassword"], + }); type FormData = z.infer; diff --git a/apps/edr-freight-web/portal/src/utils/passwordSchema.ts b/apps/edr-freight-web/portal/src/utils/passwordSchema.ts index d21d3f83e..207d9dc2b 100644 --- a/apps/edr-freight-web/portal/src/utils/passwordSchema.ts +++ b/apps/edr-freight-web/portal/src/utils/passwordSchema.ts @@ -6,7 +6,10 @@ export const passwordRequirements = [ { label: "One uppercase letter", test: (v: string) => /[A-Z]/.test(v) }, { label: "One lowercase letter", test: (v: string) => /[a-z]/.test(v) }, { label: "One number", test: (v: string) => /\d/.test(v) }, - { label: "One special character", test: (v: string) => /[^A-Za-z0-9]/.test(v) }, + { + label: "One special character", + test: (v: string) => /[^A-Za-z0-9]/.test(v), + }, ] as const; /** @@ -21,15 +24,14 @@ export const passwordField = z .regex(/\d/, "Password must include a number") .regex(/[^A-Za-z0-9]/, "Password must include a special character"); -export const confirmPasswordField = z.string().min(1, "Please confirm your password"); +export const confirmPasswordField = z + .string() + .min(1, "Please confirm your password"); -export const samePassword = (data: { password: string; confirmPassword: string }) => - data.password === data.confirmPassword; - -export const PASSWORD_MISMATCH = { - message: "Passwords do not match", - path: ["confirmPassword"], -} as const; +export const samePassword = (data: { + password: string; + confirmPassword: string; +}) => data.password === data.confirmPassword; /** Every requirement in {@link passwordRequirements} is satisfied. */ export const meetsAllRequirements = (value: string) =>