diff --git a/libs/auth/src/lib/pages/LoginPage.tsx b/libs/auth/src/lib/pages/LoginPage.tsx index c725932bc..502a4b18f 100644 --- a/libs/auth/src/lib/pages/LoginPage.tsx +++ b/libs/auth/src/lib/pages/LoginPage.tsx @@ -34,12 +34,33 @@ import type { } from "../types/auth.types"; import { useAuthConfig } from "../AuthConfig"; import { authStorage } from "../utils/auth-storage"; +const emailOrPhone = z + .string() + .trim() + .transform((value) => { + // Convert 09xxxxxxxx -> +2519xxxxxxxx + if (/^09\d{8}$/.test(value)) { + return `+251${value.substring(1)}`; + } + return value; + }) + .refine( + (value) => { + const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; + const phoneRegex = /^\+2519\d{8}$/; + + return emailRegex.test(value) || phoneRegex.test(value); + }, + { + message: "Enter a valid email or phone number (+2519xxxxxxxx)", + }, + ); const schema = z.object({ - email: z.string().email({ message: "Enter a valid email" }), + email: emailOrPhone, password: z .string() - .min(5, { message: "Password must be at least 6 characters" }), + .min(8, { message: "Password must be at least 8 characters" }), }); type FormValues = z.infer; @@ -88,8 +109,8 @@ export function LoginPage() { // `useCurrentProfile` resolves it again on demand. try { const { profile } = await profileTrigger({ - url: '/profiles/me', - method: 'GET', + url: "/profiles/me", + method: "GET", }).unwrap(); if (profile) { authStorage.setProfileId(profile.id); @@ -190,19 +211,6 @@ export function LoginPage() { - - - - - {enableSignup && ( Don't have an account?{" "}