Add logout commit for 401 response
Change the authentication logout from router to api interceptor,
so that if a user accidentally navigates to login page by clicking
the browser back button, they aren't automatically logged out.
Logouts would occur when hitting a 401 response or if the user
clicks the logout button from app header.
Signed-off-by: Yoshie Muranaka <yoshiemuranaka@gmail.com>
Change-Id: I6290070b63e724b75b3ac2fc39b3c7e814fbfc3e
diff --git a/src/store/api.js b/src/store/api.js
index 24a38e4..c8f1eda 100644
--- a/src/store/api.js
+++ b/src/store/api.js
@@ -1,5 +1,6 @@
import Axios from 'axios';
import router from '../router';
+import store from '@/store';
const api = Axios.create({
withCredentials: true
@@ -12,6 +13,8 @@
if (response.status == 401) {
if (response.config.url != '/login') {
window.location = '/login';
+ // Commit logout to remove XSRF-TOKEN cookie
+ store.commit('authentication/logout');
}
}