FitTrackee/fittrackee_client/src/api/authApi.ts
2021-11-06 21:27:32 +01:00

26 lines
615 B
TypeScript

import axios from 'axios'
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}`
if (config.headers && config.headers.Authorization !== auth) {
config.headers.Authorization = `Bearer ${authToken}`
}
}
return config
},
(error) => Promise.reject(error)
)
export default authApi