When a token-gated request comes back 401 (the session went stale), the client
silently re-authenticates if it still holds the user’s identity (i.e. they
logged in this session and never reloaded), then retries the request — so a
transient expiry self-heals without surfacing an error.
Method
Signature
Description
client.recoverSession()
() => Promise<boolean>
Attempt a silent re-auth now. Concurrent calls share one attempt. Resolves true on success. Call proactively if you like (e.g. on visibilitychange).
client.onSessionExpired(handler)
(() => void) => () => void
Fires when recovery isn’t possible — typically after a reload that kept only a now-stale token. This is your cue to route the user to the login screen. Returns an unsubscribe fn.
const off = client.onSessionExpired(() => router.push("/login"));