Asynchronous support: onRequest/onResponse
See original GitHub issueHi, is it possible to support “async for extensions before and after communication”?
Corresponding part https://github.com/nuxt-community/axios-module/blob/22a27a4cdf8c60b065a5cbae68e749da69bf9974/lib/plugin.js#L23-L28
Use Case We are using JWT of Firebase Authentication. We would like to extend the process of granting “Bearer tokens” for all or specific communications prior to communications. If the JWT has been expired, the method of getIdToken() updates it to make it a valid token before continuing with the request. Here, communication occurs before communication, and asynchronous processing should be required.
How to fix We have confirmed the operation with the following support, at least in my environment. We cloned this project and passed the test.
lib/plugin.js
onRequest(fn) {
this.interceptors.request.use(async config => await fn(config) || config)
},
onResponse(fn) {
this.interceptors.response.use(async response => await fn(response) || response)
},
Please update as a bug(?) fix if possible, Thank you in advance.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6 (1 by maintainers)
Top GitHub Comments
You Sir, are a legend! That should definitely be in the docs.
Thank you for your reply.
The code as instructed worked fine.
Just in case, I shared the sample code that I forked and modified. https://codesandbox.io/s/priceless-cartwright-5sgj7?file=/plugins/axios-extension.js
Thank you so much!