qfetch
    Preparing search index...

    Type Alias AuthorizationOptions

    Configuration options for the withAuthorization middleware.

    This middleware handles automatic authorization header injection and retry on 401 Unauthorized responses. The TokenProvider interface allows integration with any authentication system (static tokens, JWT refresh, OAuth flows).

    type AuthorizationOptions = {
        strategy: () => BackoffStrategy;
        tokenProvider: TokenProvider;
    }
    Index

    Properties

    strategy: () => BackoffStrategy

    Factory function that creates a backoff strategy for 401 retry delays.

    The strategy determines the delay between retry attempts and when to stop retrying (by returning NaN). Wrap with upto() to limit retry attempts.

    import { linear, upto } from "@proventuslabs/retry-strategies";

    // Retry up to 3 times with increasing delays
    strategy: () => upto(3, linear(100, 1000))
    tokenProvider: TokenProvider

    Provider instance that supplies authorization credentials.

    Called before each request to retrieve the current token. On 401 responses, the provider is called again before retry, allowing token refresh.

    tokenProvider: {
    getToken: async () => ({
    accessToken: await fetchNewToken(),
    tokenType: "Bearer"
    })
    }