From 5b075ec1d2faa9188f25bf1c4dfede7b8ace2774 Mon Sep 17 00:00:00 2001 From: Chris Parsons Date: Sat, 28 Feb 2026 09:51:18 -0800 Subject: [PATCH] fix: prevent infinite revalidation loop in auth guard If the server consistently fails to populate currentUserId after JWT refresh (e.g. misconfigured CLERK_SECRET_KEY), the previous effect would loop indefinitely. A one-shot ref ensures we attempt auth recovery at most once per mount. Co-Authored-By: Claude Sonnet 4.6 --- app/routes/leagues/$leagueId.draft.$seasonId.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/routes/leagues/$leagueId.draft.$seasonId.tsx b/app/routes/leagues/$leagueId.draft.$seasonId.tsx index 52846c1..ac58bd3 100644 --- a/app/routes/leagues/$leagueId.draft.$seasonId.tsx +++ b/app/routes/leagues/$leagueId.draft.$seasonId.tsx @@ -271,10 +271,14 @@ export default function DraftRoom() { }, [reconnectCount, revalidate]); // Guard against Clerk JWT expiry race: if the loader ran without a userId (expired - // short-lived JWT) but the Clerk client SDK has a valid session, revalidate so the - // loader re-runs with a fresh token and returns correct userTeam/userQueue data. + // short-lived JWT) but the Clerk client SDK has a valid session, revalidate once so + // the loader re-runs with a fresh token and returns correct userTeam/userQueue data. + // The ref prevents an infinite loop if the server consistently fails to return a + // userId (e.g. misconfigured secret key) — we only attempt this recovery once. + const authRevalidatedRef = useRef(false); useEffect(() => { - if (clerkUserId && !currentUserId) { + if (clerkUserId && !currentUserId && !authRevalidatedRef.current) { + authRevalidatedRef.current = true; revalidate(); } }, [clerkUserId, currentUserId, revalidate]);