From dd6aa0aa8f12426c681f5991f2e9a21b379e86c3 Mon Sep 17 00:00:00 2001 From: Sukanya Pandey Date: Thu, 8 Oct 2020 20:47:39 +0530 Subject: Show error toast notification on unauthorized access -When 403 status code which is an unauthorized access occured -show error toast notification. Signed-off-by: Sukanya Pandey Change-Id: I55fa7052073f87f28c3584b68fd4e84247a4237e --- src/store/api.js | 14 ++++---------- src/store/modules/GlobalStore.js | 14 +++++++++++--- 2 files changed, 15 insertions(+), 13 deletions(-) (limited to 'src/store') diff --git a/src/store/api.js b/src/store/api.js index ac1b2e36..77d94329 100644 --- a/src/store/api.js +++ b/src/store/api.js @@ -1,6 +1,4 @@ import Axios from 'axios'; -import router from '@/router'; - //Do not change store import. //Exact match alias set to support //dotenv customizations. @@ -23,14 +21,10 @@ api.interceptors.response.use(undefined, error => { } if (response.status == 403) { - if (router.history.current.name === 'unauthorized') { - // Check if current router location is unauthorized - // to avoid NavigationDuplicated errors. - // The router throws an error if trying to push to the - // same/current router location. - return; - } - router.push({ name: 'unauthorized' }); + // Check if action is unauthorized. + // Toast error message will appear on screen + // when the action is unauthorized. + store.commit('global/setUnauthorized'); } return Promise.reject(error); diff --git a/src/store/modules/GlobalStore.js b/src/store/modules/GlobalStore.js index 03301538..5af5dfe6 100644 --- a/src/store/modules/GlobalStore.js +++ b/src/store/modules/GlobalStore.js @@ -35,14 +35,16 @@ const GlobalStore = { isUtcDisplay: localStorage.getItem('storedUtcDisplay') ? JSON.parse(localStorage.getItem('storedUtcDisplay')) : true, - username: localStorage.getItem('storedUsername') + username: localStorage.getItem('storedUsername'), + isAuthorized: true }, getters: { hostStatus: state => state.hostStatus, bmcTime: state => state.bmcTime, languagePreference: state => state.languagePreference, isUtcDisplay: state => state.isUtcDisplay, - username: state => state.username + username: state => state.username, + isAuthorized: state => state.isAuthorized }, mutations: { setBmcTime: (state, bmcTime) => (state.bmcTime = bmcTime), @@ -51,7 +53,13 @@ const GlobalStore = { setLanguagePreference: (state, language) => (state.languagePreference = language), setUsername: (state, username) => (state.username = username), - setUtcTime: (state, isUtcDisplay) => (state.isUtcDisplay = isUtcDisplay) + setUtcTime: (state, isUtcDisplay) => (state.isUtcDisplay = isUtcDisplay), + setUnauthorized: state => { + state.isAuthorized = false; + window.setTimeout(() => { + state.isAuthorized = true; + }, 100); + } }, actions: { async getBmcTime({ commit }) { -- cgit v1.2.3