'use client'; import { useForm } from 'react-hook-form'; import { zodResolver } from '@hookform/resolvers/zod'; import { z } from 'zod'; import { useRouter, useSearchParams } from 'next/navigation'; import { useAuthStore } from '@/lib/auth-store'; import { useState, Suspense } from 'react'; import Link from 'next/link'; import { Train, ShieldCheck, Eye, EyeOff } from 'lucide-react'; const loginSchema = z.object({ // Accepts either an email or a phone number. Passengers who registered without an // email sign in with their phone number, which is sent in the same `email` field — // the IAM matches on either identifier. email: z.string().min(1, 'Phone or email is required'), password: z.string().min(6, 'Password must be at least 6 characters'), }); type LoginForm = z.infer; function LoginContent() { const router = useRouter(); const searchParams = useSearchParams(); const login = useAuthStore((s) => s.login); const [error, setError] = useState(''); const [loading, setLoading] = useState(false); const [showPassword, setShowPassword] = useState(false); const { register, handleSubmit, formState: { errors } } = useForm({ resolver: zodResolver(loginSchema as any), }); const onSubmit = async (data: LoginForm) => { setLoading(true); setError(''); try { await login(data.email, data.password); const redirect = searchParams.get('redirect') || '/booking/search'; router.push(redirect); } catch (err: any) { setError(err.response?.data?.message || 'Login failed. Please check your credentials.'); } finally { setLoading(false); } }; return (

Sign in

Welcome back

{error && (
{error}
)}
{errors.email && (

{errors.email.message}

)}
{errors.password && (

{errors.password.message}

)}
Forgot password?
Don't have an account? Create account
Already verified with Fayda? Set up your password
); } export default function LoginPage() { return (

Loading...

}>
); }