Fix axios error introduced in last updates

This commit is contained in:
Matthias 2023-01-05 10:26:49 +01:00
parent 2b6315966b
commit 19a479ef2b

View File

@ -1,5 +1,5 @@
import { useBotStore } from '@/stores/ftbotwrapper'; import { useBotStore } from '@/stores/ftbotwrapper';
import axios from 'axios'; import axios, { AxiosHeaders } from 'axios';
import { UserService } from './userService'; import { UserService } from './userService';
export function useApi(userService: UserService, botId: string) { export function useApi(userService: UserService, botId: string) {
@ -10,15 +10,18 @@ export function useApi(userService: UserService, botId: string) {
}); });
// Sent auth headers interceptor // Sent auth headers interceptor
api.interceptors.request.use( api.interceptors.request.use(
(config) => { (request) => {
const custconfig = config;
const token = userService.getAccessToken(); const token = userService.getAccessToken();
// Append token to each request try {
if (token) { if (token) {
// Merge custconfig dicts request.headers = request.headers as AxiosHeaders;
custconfig.headers = { ...config.headers, ...{ Authorization: `Bearer ${token}` } }; // Append token to each request
request.headers.set('Authorization', `Bearer ${token}`);
}
} catch (e) {
console.log(e);
} }
return custconfig; return request;
}, },
(error) => Promise.reject(error), (error) => Promise.reject(error),
); );