Redirect to login page when token expired

This commit is contained in:
Radhi Fadlillah 2018-06-07 15:37:07 +07:00
parent 9fa4cb2452
commit 4deed23fd4
2 changed files with 32 additions and 12 deletions

File diff suppressed because one or more lines are too long

View file

@ -283,9 +283,11 @@
this.loading = false;
})
.catch((error) => {
var errorMsg = (error.response ? error.response.data : error.message).trim();
this.loading = false;
this.showErrorDialog(errorMsg);
var errorMsg = (error.response ? error.response.data : error.message).trim();
if (errorMsg.startsWith('Token error')) this.showDialogSessionExpired(errorMsg);
else this.showErrorDialog(errorMsg);
});
},
reloadData() {
@ -398,7 +400,8 @@
})
.catch((error) => {
var errorMsg = (error.response ? error.response.data : error.message).trim();
this.showErrorDialog(errorMsg);
if (errorMsg.startsWith('Token error')) this.showDialogSessionExpired(errorMsg);
else this.showErrorDialog(errorMsg);
});
}
});
@ -460,7 +463,8 @@
})
.catch((error) => {
var errorMsg = (error.response ? error.response.data : error.message).trim();
this.showErrorDialog(errorMsg);
if (errorMsg.startsWith('Token error')) this.showDialogSessionExpired(errorMsg);
else this.showErrorDialog(errorMsg);
});
}
});
@ -511,7 +515,8 @@
})
.catch((error) => {
var errorMsg = (error.response ? error.response.data : error.message).trim();
this.showErrorDialog(errorMsg);
if (errorMsg.startsWith('Token error')) this.showDialogSessionExpired(errorMsg);
else this.showErrorDialog(errorMsg);
});
}
});
@ -558,7 +563,8 @@
})
.catch((error) => {
var errorMsg = (error.response ? error.response.data : error.message).trim();
this.showErrorDialog(errorMsg);
if (errorMsg.startsWith('Token error')) this.showDialogSessionExpired(errorMsg);
else this.showErrorDialog(errorMsg);
});
}
});
@ -627,7 +633,8 @@
})
.catch((error) => {
var errorMsg = (error.response ? error.response.data : error.message).trim();
this.showErrorDialog(errorMsg);
if (errorMsg.startsWith('Token error')) this.showDialogSessionExpired(errorMsg);
else this.showErrorDialog(errorMsg);
});
}
});
@ -643,10 +650,12 @@
this.dialogTags.loading = false;
})
.catch((error) => {
var errorMsg = (error.response ? error.response.data : error.message).trim();
this.dialogTags.loading = false;
this.dialogTags.visible = false;
this.showErrorDialog(errorMsg);
var errorMsg = (error.response ? error.response.data : error.message).trim();
if (errorMsg.startsWith('Token error')) this.showDialogSessionExpired(errorMsg);
else this.showErrorDialog(errorMsg);
});
},
showDialogLogout() {
@ -661,6 +670,17 @@
}
});
},
showDialogSessionExpired(msg) {
this.showDialog({
title: 'Error',
content: msg + '. Please login again.',
mainText: 'OK',
mainClick: () => {
Cookies.remove('token');
location.href = '/login';
}
});
},
showDialogOptions() {
this.dialogOptions.visible = true;
},