salix-front/src/boot/axios.js

22 lines
458 B
JavaScript

import axios from 'axios';
import { useSession } from 'src/composables/useSession';
const { getToken } = useSession();
axios.defaults.baseURL = '/api/';
axios.interceptors.request.use(
function (context) {
const token = getToken();
if (token.length && context.headers) {
context.headers.Authorization = token;
}
return context;
},
function (error) {
return Promise.reject(error);
}
);