import React, { useState } from 'react'; import { Link, useNavigate, useLocation } from 'react-router-dom'; import { useForm } from 'react-hook-form'; import { EyeIcon, EyeSlashIcon } from '@heroicons/react/24/outline'; import { useAuth } from '../../hooks/useAuth'; import LoadingSpinner from '../../components/UI/LoadingSpinner'; const Login = () => { const [showPassword, setShowPassword] = useState(false); const { login, loading } = useAuth(); const navigate = useNavigate(); const location = useLocation(); const from = location.state?.from?.pathname || '/dashboard'; const { register, handleSubmit, formState: { errors }, setError, } = useForm(); const onSubmit = async (data) => { const result = await login(data); if (result.success) { navigate(from, { replace: true }); } else { setError('root', { type: 'manual', message: result.error }); } }; const handleGoogleLogin = () => { // Redirect to Google OAuth endpoint window.location.href = `${process.env.REACT_APP_API_URL || 'http://localhost:5000'}/api/auth/google`; }; return (

Sign in to your account

Or{' '} create a new account

{errors.root && (

{errors.root.message}

)}
{errors.email && (

{errors.email.message}

)}
{errors.password && (

{errors.password.message}

)}
Forgot your password?
Or continue with
); }; export default Login;