Skip to content

Commit

Permalink
optimized logout process
Browse files Browse the repository at this point in the history
  • Loading branch information
tikazyq committed Nov 20, 2021
1 parent 510df08 commit fd204a6
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/services/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@ export const initRequest = (router?: Router) => {
}, err => {
const status = err?.response?.status;
if (status === 401) {
if (msgBoxVisible) return;
msgBoxVisible = true;
ElMessageBox.confirm('You seem to have been logged-out, try to login again?', 'Unauthorized', {type: 'warning'})
.then(_ => router?.push('/login'))
.finally(() => {
msgBoxVisible = false;
});
if (window.localStorage.getItem('token')) {
// token expired, popup logout warning
if (msgBoxVisible) return;
msgBoxVisible = true;
ElMessageBox.confirm('You seem to have been logged-out, try to login again?', 'Unauthorized', {type: 'warning'})
.then(_ => router?.push('/login'))
.finally(() => {
msgBoxVisible = false;
});
} else {
// token not exists, redirect to login page
router?.push('/login');
}
} else {
console.error(err);
}
Expand Down

0 comments on commit fd204a6

Please sign in to comment.