Projekt

Obecné

Profil

Stáhnout (847 Bajtů) Statistiky
| Větev: | Tag: | Revize:
1 c7d2ced1 Václav Honzík
import axios from 'axios'
2
import { Store } from 'redux'
3
import config from '../config/conf'
4
import { AppStore } from '../features/redux/store'
5
6
let store: AppStore // this will get injected later
7
8
export const injectStore = (_store: Store) => {
9
    store = _store
10
}
11
12
const axiosInstance = axios.create({
13
    baseURL: config.baseUrl,
14
})
15
16
axiosInstance.interceptors.request.use(config => {
17
    config.headers = {
18
        ...config.headers,
19 a69da1e3 Vaclav Honzik
        Authorization: store.getState().user.accessToken ?? ''
20 c7d2ced1 Václav Honzík
    }
21
})
22
23
axiosInstance.interceptors.response.use(response => response, error => {
24
25
    if (error?.response?.status === 401) {
26 a69da1e3 Vaclav Honzik
        const refreshToken = store.getState().user.refreshToken
27 c7d2ced1 Václav Honzík
        // TODO send the refresh token correctly
28
        console.log('401 called they want their token refreshed');
29
    }
30
31
})
32
33
export default axiosInstance