typesense / typesense-js

JavaScript / TypeScript client for Typesense
https://typesense.org/docs/api
Apache License 2.0
400 stars 74 forks source link

Is Axios interceptors available through Typesense.Client? #223

Open henriksjodahl opened 3 weeks ago

henriksjodahl commented 3 weeks ago

Description

I’m working on using typesense-js in a Nuxt application, and I have the goal to manage access to my data by rotating and scoping API-keys through my backend with a fixed ttl. But I'm looking for a way to easily capture any old keys and refreshing them by looking for 401-exceptions through the API. Since you’re using axios I assumed I could use Axios interceptors in a way, but looking through the code i cant seem to find a way to do that. Am I missing something, or is there actually no way to pass interceptors down to the Axios client inside Typesense.Client?

Expected Behavior

A way to pass Axios Interceptors through the Typesense Client.

Actual Behavior

There seem to be no way to pass down Axios Interceptors through the Typesense Client.

jasonbosco commented 2 weeks ago

There is no way to pass interceptors to the axios instance used by typesense-js.

However, you should be able to use global interceptors as described here: https://axios-http.com/docs/interceptors

henriksjodahl commented 2 weeks ago

Thanks for the reply!

I've tried this, but from what I've read, I don't think global interceptors are automatically copied over when a new Axios-instance is created. I can't seem to get them registered within the TypeSense Axios-instance at least.