Function createApiClient

  • Create an axios instance preconfigured for token-authenticated APIs.

    The returned client sends JSON, attaches Authorization: Bearer <token> from tokenStore to every request, and clears the token plus emits auth:unauthorized on any 401 response.

    Use this for any backend that shares the same login as the auth server; for unauthenticated endpoints a plain axios instance is fine.

    Parameters

    • baseURL: string

      Root URL prefixed to every request (for example "https://api.example.com").

    Returns AxiosInstance

    A configured AxiosInstance.

    const api = createApiClient("https://api.example.com");
    const { data } = await api.get("/expenses"); // Authorization added automatically