26 lines
615 B
TypeScript
Raw Normal View History

import axios from 'axios'
2021-08-11 22:21:26 +02:00
import store from '@/store'
import { AUTH_USER_STORE } from '@/store/constants'
import { getApiUrl } from '@/utils'
const authApi = axios.create({
baseURL: getApiUrl(),
})
authApi.interceptors.request.use(
(config) => {
const authToken = store.getters[AUTH_USER_STORE.GETTERS.AUTH_TOKEN]
if (authToken) {
const auth = `Bearer ${authToken}`
2021-11-06 21:27:23 +01:00
if (config.headers && config.headers.Authorization !== auth) {
config.headers.Authorization = `Bearer ${authToken}`
}
}
return config
},
(error) => Promise.reject(error)
)
export default authApi