From 48d3335f1289829cc6fe09f775f4363b796f64ec Mon Sep 17 00:00:00 2001 From: Sean O'Connor Date: Thu, 11 Jun 2026 12:09:22 -0400 Subject: [PATCH] fix: auth redir memoization --- src/components/AuthRedirect.tsx | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/components/AuthRedirect.tsx b/src/components/AuthRedirect.tsx index 1a69127..384140d 100644 --- a/src/components/AuthRedirect.tsx +++ b/src/components/AuthRedirect.tsx @@ -5,16 +5,27 @@ import { useRouter } from "next/navigation"; import { useEffect } from "react"; export function AuthRedirect() { - const { data: session, isPending } = authClient.useSession(); - // const session = { user: null }; const isPending = false; const router = useRouter(); useEffect(() => { - // Only redirect if we're sure the user is authenticated - if (!isPending && session?.user) { - router.push("/dashboard"); + let isCurrent = true; + + async function redirectAuthenticatedUser() { + const { data: session } = await authClient.getSession().catch(() => ({ + data: null, + })); + + if (isCurrent && session?.user) { + router.push("/dashboard"); + } } - }, [session, isPending, router]); + + void redirectAuthenticatedUser(); + + return () => { + isCurrent = false; + }; + }, [router]); // This component doesn't render anything return null;