Stirling-Tools/Stirling-PDF · error · Error
Timed out waiting for anonymous session token
Error message
Timed out waiting for anonymous session token
What it means
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.
Source
Thrown at frontend/editor/src/saas/hooks/useAutoAnonymousAuth.ts:92
const triggerAnonymousAuth = useCallback(async () => {
if (state.isAutoAuthenticating) return;
setState((prev) => ({
...prev,
isAutoAuthenticating: true,
autoAuthError: null,
}));
try {
console.log("[useAutoAnonymousAuth] anonymous auth starting");
const { error } = await signInAnonymously();
if (error) throw error;
// Wait for a usable token so first API calls won't 401/redirect
const ok = await waitForToken(7000);
if (!ok) {
throw new Error("Timed out waiting for anonymous session token");
}
console.log("[useAutoAnonymousAuth] anonymous auth complete");
setState((prev) => ({
...prev,
isAutoAuthenticating: false,
shouldTriggerAutoAuth: false,
}));
} catch (e) {
console.error("[useAutoAnonymousAuth] anonymous auth failed", e);
setState((prev) => ({
...prev,
isAutoAuthenticating: false,
autoAuthError:
e instanceof Error ? e.message : "Anonymous authentication failed",
}));
}
}, [state.isAutoAuthenticating, waitForToken]);View on GitHub (pinned to 9ef20dcab8)
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)
Example fix
// before const ok = await waitForToken(7000); // after const ok = await waitForToken(12000); // accommodate high-latency regions
Defensive patterns
Strategy: retry
Validate before calling
// Check localStorage availability before relying on anonymous auth
function isStorageAvailable(): boolean {
try {
const k = '__test__';
localStorage.setItem(k, '1');
localStorage.removeItem(k);
return true;
} catch {
return false;
}
}
if (!isStorageAvailable()) {
// Fall back to a non-anonymous prompt or show an error
} Try / catch
// The hook already catches internally; expose autoAuthError to the UI:
const { autoAuthError, isAutoAuthenticating } = useAutoAnonymousAuth();
useEffect(() => {
if (autoAuthError) {
showAuthErrorBanner(autoAuthError);
}
}, [autoAuthError]); Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
- Timeouts: ETIMEDOUT, deadlines, and hung requests — what actually expires when a request times out.
Related errors
- Sign up failed
- No SaaS session — admin must link an account before attended
- No SaaS session
- error.message
- Unknown error occurred during signup
AI-assisted analysis of Stirling-Tools/Stirling-PDF@9ef20dcab8 (2026-08-13).
Data as JSON: /api/errors/588719cf9713142c.
Report an issue: GitHub.