@me2em/react
    Preparing search index...

    Function useSession

    • Hook that creates and manages a signed session token for a Handle.

      When handle is provided, creates a Session with the given options. Supports auto-renewal: when autoRenew is true (default), a timer fires at half the session TTL to create a fresh session with a new jti (the previous token remains valid until its own expiry, but the lineage identity is preserved through handle). Background tabs throttle (clamped wakeups) or fully suspend timers, so on return to visibility the hook additionally renews proactively when the session is already past its half-life point (BL-51) — the overdue timer path alone could leave the first user actions racing an expired session.

      On unmount, all timers are cleaned up to prevent state updates after the component is gone.

      Dependencies: [handle, renew] — the options object is read through a ref, so passing a fresh object literal on every render does NOT re-trigger session creation. Only changes to handle (or to the renewal function identity, which follows handle) do.

      Parameters

      • handle: Handle | null

        The Handle to sign the session, or null.

      • options: UseSessionOptions

        Session options (audience, scopes, ttl).

      • autoRenew: boolean = true

        Whether to auto-renew at half-life (default: true).

      Returns UseSessionResult

      Session state with manual renew control.

      const handle = useHandle('my-handle');
      const { session, isExpired, renew } = useSession(handle, {
      audience: 'app.example.com',
      scopes: ['read', 'write'],
      ttl: 3600,
      });