From 339dd6db942774059a2f635e82f2c8667e6a5a07 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Wed, 17 Jan 2024 06:14:04 +0000 Subject: [PATCH] refactor: interceptor --- packages/nc-gui/composables/useApi/interceptors.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/nc-gui/composables/useApi/interceptors.ts b/packages/nc-gui/composables/useApi/interceptors.ts index cf6032b2a0..b2d74aef7b 100644 --- a/packages/nc-gui/composables/useApi/interceptors.ts +++ b/packages/nc-gui/composables/useApi/interceptors.ts @@ -11,7 +11,9 @@ export function addAxiosInterceptors(api: Api) { const route = router.currentRoute const optimisedQuery = useState('optimisedQuery', () => true) - api.instance.interceptors.request.use((config) => { + const axiosInstance = api.instance; + + axiosInstance.interceptors.request.use((config) => { config.headers['xc-gui'] = 'true' if (state.token.value) config.headers['xc-auth'] = state.token.value @@ -38,7 +40,7 @@ export function addAxiosInterceptors(api: Api) { }) // Return a successful response back to the calling service - api.instance.interceptors.response.use( + axiosInstance.interceptors.response.use( (response) => { return response }, @@ -70,7 +72,7 @@ export function addAxiosInterceptors(api: Api) { return new Promise((resolve, reject) => { const config = error.config config.headers['xc-auth'] = token - api.instance + axiosInstance .request(config) .then((response) => { resolve(response) @@ -96,7 +98,7 @@ export function addAxiosInterceptors(api: Api) { } // Try request again with new token - return api.instance + return axiosInstance .post('/auth/token/refresh', null, { withCredentials: true, }) @@ -111,7 +113,7 @@ export function addAxiosInterceptors(api: Api) { refreshTokenPromise = null return new Promise((resolve, reject) => { - api.instance + axiosInstance .request(config) .then((response) => { resolve(response)