Skip to content

Instantly share code, notes, and snippets.

@danielstgt
Last active August 18, 2020 19:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielstgt/cfe1094dd58cbae522c30cdc4f656ef6 to your computer and use it in GitHub Desktop.
Save danielstgt/cfe1094dd58cbae522c30cdc4f656ef6 to your computer and use it in GitHub Desktop.
axios interceptor for expired sessions with SweetAlert
axios.interceptors.response.use(response => {
return response;
}, error => {
if (error.response.status === 401) {
Swal.fire({
title: 'Session expired',
text: 'Please sign in again!',
type: 'error',
}).then(result => {
if (result.value) {
location.reload();
}
});
}
return Promise.reject(error);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment