diff --git a/src/app/login/page.tsx b/src/app/login/page.tsx index 4c347e1..572ff92 100644 --- a/src/app/login/page.tsx +++ b/src/app/login/page.tsx @@ -5,6 +5,7 @@ import { useRouter } from 'next/navigation'; import Link from 'next/link'; import { Mail, Lock } from 'lucide-react'; import { useAuth } from '@/lib/auth-context'; +import { useRedirectIfAuthenticated } from '@/lib/use-redirect-if-authenticated'; import { ApiError } from '@/lib/api'; import { FormError } from '@/components/form-error'; import { AuthLayout } from '@/components/auth-layout'; @@ -18,6 +19,7 @@ export default function LoginPage() { const [password, setPassword] = useState(''); const [error, setError] = useState(null); const [submitting, setSubmitting] = useState(false); + const redirecting = useRedirectIfAuthenticated(); async function handleSubmit(e: React.FormEvent) { e.preventDefault(); @@ -37,6 +39,9 @@ export default function LoginPage() { } } + // Signed-in users are sent to their dashboard instead of seeing the form (#50). + if (redirecting) return null; + return (
diff --git a/src/app/register/page.tsx b/src/app/register/page.tsx index e40b6a6..cf00d08 100644 --- a/src/app/register/page.tsx +++ b/src/app/register/page.tsx @@ -5,6 +5,7 @@ import { useRouter } from 'next/navigation'; import Link from 'next/link'; import { User, Mail, Lock } from 'lucide-react'; import { useAuth } from '@/lib/auth-context'; +import { useRedirectIfAuthenticated } from '@/lib/use-redirect-if-authenticated'; import { ApiError } from '@/lib/api'; import { FormError } from '@/components/form-error'; import { AuthLayout } from '@/components/auth-layout'; @@ -19,6 +20,7 @@ export default function RegisterPage() { const [password, setPassword] = useState(''); const [error, setError] = useState(null); const [submitting, setSubmitting] = useState(false); + const redirecting = useRedirectIfAuthenticated(); async function handleSubmit(e: React.FormEvent) { e.preventDefault(); @@ -38,6 +40,9 @@ export default function RegisterPage() { } } + // Signed-in users are sent to their dashboard instead of seeing the form (#50). + if (redirecting) return null; + return ( { + if (!loading && user) router.replace(to); + }, [loading, user, router, to]); + + return loading || user !== null; +}