update instance
This commit is contained in:
1 parent
ee99215af4
commit
63b38f177b
2 files changed
+20
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import router from '@/router';
|
||||
import store from '@/store';
|
||||
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
|
||||
|
||||
@@ -17,6 +18,20 @@ httpClient.interceptors.request.use((config) => {
|
||||
return config;
|
||||
});
|
||||
|
||||
httpClient.interceptors.response.use(
|
||||
(response) => {
|
||||
return response;
|
||||
},
|
||||
(error) => {
|
||||
console.log('error', error);
|
||||
if (error.response.status === 401) {
|
||||
store.dispatch('resetAuth');
|
||||
router.push('/');
|
||||
}
|
||||
return error;
|
||||
}
|
||||
);
|
||||
|
||||
// const httpClient = (options: AxiosRequestConfig): Promise<AxiosResponse> => instance.request(options);
|
||||
|
||||
export default httpClient;
|
||||
@@ -36,6 +36,11 @@ const store = createStore({
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
resetAuth({ commit }) {
|
||||
commit('setRefreshToken', undefined);
|
||||
commit('setAccessToken', undefined);
|
||||
commit('setUser', undefined);
|
||||
},
|
||||
setRefreshToken({ commit }: ActionContext<IState, IState>, payload: string) {
|
||||
commit('setRefreshToken', payload);
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user