diff options
Diffstat (limited to 'src/store/modules/Authentication')
-rw-r--r-- | src/store/modules/Authentication/AuthenticanStore.js | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/src/store/modules/Authentication/AuthenticanStore.js b/src/store/modules/Authentication/AuthenticanStore.js index 0dd616a9..c42b9da1 100644 --- a/src/store/modules/Authentication/AuthenticanStore.js +++ b/src/store/modules/Authentication/AuthenticanStore.js @@ -6,31 +6,39 @@ const AuthenticationStore = { namespaced: true, state: { authError: false, - cookie: Cookies.get('XSRF-TOKEN') + xsrfCookie: Cookies.get('XSRF-TOKEN'), + isAuthenticatedCookie: Cookies.get('IsAuthenticated') }, getters: { authError: state => state.authError, - isLoggedIn: state => !!state.cookie, - token: state => state.cookie + isLoggedIn: state => { + return ( + state.xsrfCookie !== undefined || state.isAuthenticatedCookie == 'true' + ); + }, + token: state => state.xsrfCookie }, mutations: { authSuccess(state) { state.authError = false; - state.cookie = Cookies.get('XSRF-TOKEN'); + state.xsrfCookie = Cookies.get('XSRF-TOKEN'); }, authError(state, authError = true) { state.authError = authError; }, - logout() { + logout(state) { Cookies.remove('XSRF-TOKEN'); + Cookies.remove('IsAuthenticated'); localStorage.removeItem('storedUsername'); + state.xsrfCookie = undefined; + state.isAuthenticatedCookie = undefined; } }, actions: { - login({ commit }, auth) { + login({ commit }, { username, password }) { commit('authError', false); return api - .post('/login', { data: auth }) + .post('/login', { data: [username, password] }) .then(() => commit('authSuccess')) .catch(error => { commit('authError'); @@ -49,6 +57,11 @@ const AuthenticationStore = { .get(`/redfish/v1/AccountService/Accounts/${username}`) .then(({ data: { PasswordChangeRequired } }) => PasswordChangeRequired) .catch(error => console.log(error)); + }, + resetStoreState({ state }) { + state.authError = false; + state.xsrfCookie = Cookies.get('XSRF-TOKEN'); + state.isAuthenticatedCookie = Cookies.get('IsAuthenticated'); } } }; |