From 9e822b207333784bc0b226c8362d05dde9bce5b3 Mon Sep 17 00:00:00 2001 From: Chris Parsons Date: Fri, 24 Apr 2026 23:27:52 -0700 Subject: [PATCH] Keep session alive during long drafts with a 15-minute ping Co-Authored-By: Claude Sonnet 4.6 --- app/hooks/useDraftAuthRecovery.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) 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);