Handle logout on invalid token

This commit is contained in:
jeffvli
2022-10-29 18:57:23 -07:00
parent 97b383ff0b
commit ff6882a6cd
+5 -16
View File
@@ -1,5 +1,6 @@
/* eslint-disable no-underscore-dangle */
import Axios from 'axios';
import { useAuthStore } from '@/renderer/store';
import { authApi } from '../api/auth.api';
export const ax = Axios.create({
@@ -60,24 +61,12 @@ ax.interceptors.response.use(
return Axios(config);
}
localStorage.setItem(
'store_authentication',
JSON.stringify({
...auth,
state: { ...auth.state, accessToken: '', refreshToken: '' },
})
);
const { logout } = useAuthStore.getState();
if (err.response.data.error.message === 'No auth token') {
localStorage.setItem(
'store_authentication',
JSON.stringify({
...auth,
state: { ...auth.state, accessToken: '', refreshToken: '' },
})
);
// window.location.reload();
logout();
}
logout();
}
return Promise.reject(err);
}