{"record":{"id":"588719cf9713142c","repo":"Stirling-Tools/Stirling-PDF","slug":"timed-out-waiting-for-anonymous-session-token","errorCode":null,"errorMessage":"Timed out waiting for anonymous session token","messagePattern":"Timed out waiting for anonymous session token","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"frontend/editor/src/saas/hooks/useAutoAnonymousAuth.ts","lineNumber":92,"sourceCode":"\n  const triggerAnonymousAuth = useCallback(async () => {\n    if (state.isAutoAuthenticating) return;\n\n    setState((prev) => ({\n      ...prev,\n      isAutoAuthenticating: true,\n      autoAuthError: null,\n    }));\n    try {\n      console.log(\"[useAutoAnonymousAuth] anonymous auth starting\");\n\n      const { error } = await signInAnonymously();\n      if (error) throw error;\n\n      // Wait for a usable token so first API calls won't 401/redirect\n      const ok = await waitForToken(7000);\n      if (!ok) {\n        throw new Error(\"Timed out waiting for anonymous session token\");\n      }\n\n      console.log(\"[useAutoAnonymousAuth] anonymous auth complete\");\n      setState((prev) => ({\n        ...prev,\n        isAutoAuthenticating: false,\n        shouldTriggerAutoAuth: false,\n      }));\n    } catch (e) {\n      console.error(\"[useAutoAnonymousAuth] anonymous auth failed\", e);\n      setState((prev) => ({\n        ...prev,\n        isAutoAuthenticating: false,\n        autoAuthError:\n          e instanceof Error ? e.message : \"Anonymous authentication failed\",\n      }));\n    }\n  }, [state.isAutoAuthenticating, waitForToken]);","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/Stirling-Tools/Stirling-PDF/blob/9ef20dcab80b85041912f045e17a6aea1d08f969/frontend/editor/src/saas/hooks/useAutoAnonymousAuth.ts#L74-L110","documentation":"Thrown by useAutoAnonymousAuth when signInAnonymously() succeeds but waitForToken(7000) cannot find an access_token in the Supabase session within 7 seconds. The hook polls supabase.auth.getSession() every 120ms and also listens to onAuthStateChange; if neither yields a token within the window, the auth is treated as failed. The error is caught internally and surfaced as autoAuthError state rather than propagated.","triggerScenarios":"signInAnonymously() returns no error but the session isn't persisted to localStorage fast enough; the Supabase project is in a geographically distant region adding latency; the browser has localStorage disabled (privacy mode, strict cookie policy); an ad-blocker or extension interferes with the Supabase JS client's network/storage.","commonSituations":"Supabase project hosted in a different region than the user (high RTT); browser in private/incognito mode with storage restrictions; ad-blocker or privacy extension blocking Supabase API calls; Supabase project under rate-limiting or temporary degraded service.","solutions":["Increase the waitForToken timeout beyond 7000ms to accommodate high-latency regions","Verify the Supabase project region is close to the user base","Check that anonymous sign-in is enabled in Supabase Dashboard > Authentication > Sign In Providers","Test in a clean browser profile without extensions to rule out ad-blocker interference","Verify localStorage is accessible (open DevTools > Application > Local Storage)"],"exampleFix":"// before\nconst ok = await waitForToken(7000);\n\n// after\nconst ok = await waitForToken(12000); // accommodate high-latency regions","handlingStrategy":"retry","validationCode":"// Check localStorage availability before relying on anonymous auth\nfunction isStorageAvailable(): boolean {\n  try {\n    const k = '__test__';\n    localStorage.setItem(k, '1');\n    localStorage.removeItem(k);\n    return true;\n  } catch {\n    return false;\n  }\n}\nif (!isStorageAvailable()) {\n  // Fall back to a non-anonymous prompt or show an error\n}","typeGuard":null,"tryCatchPattern":"// The hook already catches internally; expose autoAuthError to the UI:\nconst { autoAuthError, isAutoAuthenticating } = useAutoAnonymousAuth();\nuseEffect(() => {\n  if (autoAuthError) {\n    showAuthErrorBanner(autoAuthError);\n  }\n}, [autoAuthError]);","preventionTips":["Verify anonymous auth is enabled in Supabase Dashboard > Authentication > Providers","Test in a clean browser profile to rule out extension/ad-blocker interference with Supabase storage","Increase the waitForToken timeout for deployments serving users in high-latency regions","Check localStorage availability in privacy/incognito mode before triggering anonymous auth"],"tags":["auth","anonymous","supabase","timeout","saas","session"],"backgroundTag":null,"analyzedSha":"9ef20dcab80b85041912f045e17a6aea1d08f969","analyzedAt":"2026-08-13T22:11:39.827Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}