Projekt

Obecné

Profil

Stáhnout (847 Bajtů) Statistiky
| Větev: | Tag: | Revize:
1
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
        Authorization: store.getState().user.accessToken ?? ''
20
    }
21
})
22

    
23
axiosInstance.interceptors.response.use(response => response, error => {
24

    
25
    if (error?.response?.status === 401) {
26
        const refreshToken = store.getState().user.refreshToken
27
        // TODO send the refresh token correctly
28
        console.log('401 called they want their token refreshed');
29
    }
30

    
31
})
32

    
33
export default axiosInstance
    (1-1/1)