26 lines
615 B
TypeScript
26 lines
615 B
TypeScript
import axios from 'axios'
|
|
|
|
const customAxios = axios.create({
|
|
baseURL: import.meta.env.TAOBIN_RECIPE_MANAGER_SERVER_URL ?? 'http://localhost:8080',
|
|
withCredentials: true
|
|
})
|
|
|
|
customAxios.interceptors.response.use(
|
|
res => res,
|
|
err => {
|
|
const originalRequest = err.config
|
|
|
|
if (err.response.status === 401 && !originalRequest._retry) {
|
|
originalRequest._retry = true
|
|
return customAxios.get('/auth/refresh').then(res => {
|
|
if (res.status === 200) {
|
|
return customAxios(originalRequest)
|
|
}
|
|
})
|
|
}
|
|
|
|
return Promise.reject(err)
|
|
}
|
|
)
|
|
|
|
export default customAxios
|