fix: auth redir memoization

This commit is contained in:
2026-06-11 12:09:22 -04:00
parent 1c24c90189
commit 48d3335f12
+17 -6
View File
@@ -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;