diff --git a/app/hooks/useDraftAuthRecovery.ts b/app/hooks/useDraftAuthRecovery.ts index 7c28fe3..fcb6988 100644 --- a/app/hooks/useDraftAuthRecovery.ts +++ b/app/hooks/useDraftAuthRecovery.ts @@ -118,6 +118,17 @@ export function useDraftAuthRecovery({ }; }, [currentUserId, authDegraded, revalidate]); + // Periodically ping the session endpoint to keep it alive during long drafts. + useEffect(() => { + if (authDegraded) return; + const FIFTEEN_MINUTES = 15 * 60 * 1000; + const id = setInterval(async () => { + const { data: session } = await authClient.getSession(); + if (!session) setAuthDegraded(true); + }, FIFTEEN_MINUTES); + return () => clearInterval(id); + }, [authDegraded]); + // Track revalidation lifecycle to sync local state from fresh loader data. const revalidatorStateRef = useRef(revalidatorState); const isRevalidatingRef = useRef(false);