Client - init login and getting user profile
This commit is contained in:
24
fittrackee_client/src/api/authApi.ts
Normal file
24
fittrackee_client/src/api/authApi.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import axios from 'axios'
|
||||
import store from '@/store'
|
||||
import { USER_STORE } from '@/store/constants'
|
||||
import { getApiUrl } from '@/utils'
|
||||
|
||||
const authApi = axios.create({
|
||||
baseURL: getApiUrl(),
|
||||
})
|
||||
|
||||
authApi.interceptors.request.use(
|
||||
(config) => {
|
||||
const authToken = store.getters[USER_STORE.GETTERS.AUTH_TOKEN]
|
||||
if (authToken) {
|
||||
const auth = `Bearer ${authToken}`
|
||||
if (config.headers.Authorization !== auth) {
|
||||
config.headers.Authorization = `Bearer ${authToken}`
|
||||
}
|
||||
}
|
||||
return config
|
||||
},
|
||||
(error) => Promise.reject(error)
|
||||
)
|
||||
|
||||
export default authApi
|
8
fittrackee_client/src/api/defaultApi.ts
Normal file
8
fittrackee_client/src/api/defaultApi.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import axios from 'axios'
|
||||
import { getApiUrl } from '@/utils'
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: getApiUrl(),
|
||||
})
|
||||
|
||||
export default api
|
Reference in New Issue
Block a user