import { useAuth } from '../contexts/AuthContext' import { useNavigate } from 'react-router-dom' import { useEffect, useState } from 'react' import { GoogleSignInButton } from '../components/GoogleSignInButton' import { LoginCard } from '../components/LoginCard' export default function LoginPage() { const { user, loading, signInWithGoogle } = useAuth() const navigate = useNavigate() const [signingIn, setSigningIn] = useState(false) const [error, setError] = useState(null) useEffect(() => { if (loading) return if (user) { navigate('/', { replace: true }) } }, [user, loading, navigate]) async function handleGoogleSignIn() { setError(null) setSigningIn(true) try { await signInWithGoogle() } catch (e) { setError(e instanceof Error ? e.message : 'Sign-in failed') } finally { setSigningIn(false) } } if (loading) { return (

Loading…

) } return (
{error && (

{error}

)}
) }