Skip to content

Provide custom AxiosInstance to H5GroveProvider #1800

@KirmTwinty

Description

@KirmTwinty

Is your feature request related to a problem?

The current H5GroveProvider only allows configuration of the Axios client through the axiosConfig?: AxiosRequestConfig property.
However, in some cases, it is more useful to provide a fully customized Axios instance, which may include additional features such as interceptors.

Requested solution or feature

One simple solution can be to provide a custom derived H5GroveApiAxiosInstance that override the client, and then a new H5GroveCustomProvider (code not provided here):

import axios, {
    AxiosInstance
}
import h5grove, {
    DataProviderApi,
    H5GroveApi
}

export class H5GroveApiAxiosInstance extends H5GroveApi {
    private readonly client: AxiosInstance;

    public constructor(
	url: string,
	filepath: string,
	axiosClient?: AxiosInstance,
    private readonly _getExportURL?: DataProviderApi['getExportURL'],
    ) {
	super(filepath);

	this.client = axiosClient
    }
}

Alternatives you've considered

Directly modify the H5GroveProvider & H5GroveApi.

Additional context

In our application, for example, we use interceptors to ensure that the current user has a valid token, refresh it when necessary, and handle other authentication-related logic.

PS: thanks for the actual developments!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions