Fix bug with token refresh

This commit is contained in:
Matthias 2020-06-23 20:38:02 +02:00
parent c5eadc3d3d
commit 53c4641e8a
2 changed files with 9 additions and 9 deletions

View File

@ -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 ?
}

View File

@ -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}` },