'use client'; import { useState } from 'react'; import { useRouter } from 'next/navigation'; import { Box, TextField, Button, Typography, Paper, InputAdornment, IconButton, Divider, Alert, CircularProgress, Link as MuiLink, } from '@mui/material'; import { Visibility, VisibilityOff, Google, Apple } from '@mui/icons-material'; import { useForm } from 'react-hook-form'; import { zodResolver } from '@hookform/resolvers/zod'; import { motion } from 'framer-motion'; import * as z from 'zod'; import { useAuth } from '@/lib/auth/AuthContext'; import Link from 'next/link'; const loginSchema = z.object({ email: z.string().email('Invalid email address'), password: z.string().min(8, 'Password must be at least 8 characters'), }); type LoginFormData = z.infer; export default function LoginPage() { const [showPassword, setShowPassword] = useState(false); const [error, setError] = useState(null); const [isLoading, setIsLoading] = useState(false); const { login } = useAuth(); const router = useRouter(); const { register, handleSubmit, formState: { errors }, } = useForm({ resolver: zodResolver(loginSchema), }); const onSubmit = async (data: LoginFormData) => { setError(null); setIsLoading(true); try { await login(data); // Navigation is handled in the login function } catch (err: any) { setError(err.message || 'Failed to login. Please check your credentials.'); } finally { setIsLoading(false); } }; return ( Welcome Back 👋 Sign in to continue tracking your child's journey {error && ( {error} )} setShowPassword(!showPassword)} edge="end" disabled={isLoading} > {showPassword ? : } ), }} /> Forgot password? OR Don't have an account?{' '} Sign up ); }