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 <noreply@anthropic.com>
This commit is contained in:
parent
d21ff5d977
commit
5b075ec1d2
1 changed files with 7 additions and 3 deletions
|
|
@ -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]);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue