mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-09 20:29:36 +02:00
Handle logout on invalid token
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
/* eslint-disable no-underscore-dangle */
|
/* eslint-disable no-underscore-dangle */
|
||||||
import Axios from 'axios';
|
import Axios from 'axios';
|
||||||
|
import { useAuthStore } from '@/renderer/store';
|
||||||
import { authApi } from '../api/auth.api';
|
import { authApi } from '../api/auth.api';
|
||||||
|
|
||||||
export const ax = Axios.create({
|
export const ax = Axios.create({
|
||||||
@@ -60,24 +61,12 @@ ax.interceptors.response.use(
|
|||||||
return Axios(config);
|
return Axios(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
localStorage.setItem(
|
const { logout } = useAuthStore.getState();
|
||||||
'store_authentication',
|
|
||||||
JSON.stringify({
|
|
||||||
...auth,
|
|
||||||
state: { ...auth.state, accessToken: '', refreshToken: '' },
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
if (err.response.data.error.message === 'No auth token') {
|
if (err.response.data.error.message === 'No auth token') {
|
||||||
localStorage.setItem(
|
logout();
|
||||||
'store_authentication',
|
|
||||||
JSON.stringify({
|
|
||||||
...auth,
|
|
||||||
state: { ...auth.state, accessToken: '', refreshToken: '' },
|
|
||||||
})
|
|
||||||
);
|
|
||||||
// window.location.reload();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logout();
|
||||||
}
|
}
|
||||||
return Promise.reject(err);
|
return Promise.reject(err);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user