From 53c4641e8a6a24143703315fb9e1b5f21406e833 Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 23 Jun 2020 20:38:02 +0200 Subject: [PATCH] Fix bug with token refresh --- src/shared/apiService.ts | 14 ++++++-------- src/shared/userService.ts | 4 +++- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/shared/apiService.ts b/src/shared/apiService.ts index 621a4afe..594f0734 100644 --- a/src/shared/apiService.ts +++ b/src/shared/apiService.ts @@ -1,11 +1,9 @@ import axios from 'axios'; import userService from './userService'; -export const apiBase = '/api/v1'; - export const api = axios.create({ - baseURL: apiBase, - timeout: 1000, + baseURL: userService.apiBase, + timeout: 2000, withCredentials: true, }); @@ -43,11 +41,11 @@ api.interceptors.response.use( export function setBaseUrl(baseURL: string) { if (baseURL === null) { // Reset to "local" baseurl - api.defaults.baseURL = apiBase; - } else if (!baseURL.endsWith(apiBase)) { - api.defaults.baseURL = `${baseURL}${apiBase}`; + api.defaults.baseURL = userService.apiBase; + } else if (!baseURL.endsWith(userService.apiBase)) { + api.defaults.baseURL = `${baseURL}${userService.apiBase}`; } else { - api.defaults.baseURL = `${baseURL}`; + api.defaults.baseURL = `${baseURL}${userService.apiBase}`; } // Do some more testing here ? } diff --git a/src/shared/userService.ts b/src/shared/userService.ts index aeff412e..923863e7 100644 --- a/src/shared/userService.ts +++ b/src/shared/userService.ts @@ -3,8 +3,10 @@ import axios from 'axios'; const AUTH_REF_TOKEN = 'auth_ref_token'; const AUTH_ACCESS_TOKEN = 'auth_access_token'; const AUTH_API_URL = 'auth_api_url'; +const apiBase = '/api/v1'; export default { + apiBase, AUTH_API_URL, setAPIUrl(apiurl) { localStorage.setItem(AUTH_API_URL, JSON.stringify(apiurl)); @@ -52,7 +54,7 @@ export default { console.log(apiurl); axios .post( - `${this.getAPIUrl()}/token/refresh`, + `${this.getAPIUrl()}/${apiBase}/token/refresh`, {}, { headers: { Authorization: `Bearer ${token}` },