diff options
Diffstat (limited to 'src/store/modules/Authentication')
-rw-r--r-- | src/store/modules/Authentication/AuthenticanStore.js | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/src/store/modules/Authentication/AuthenticanStore.js b/src/store/modules/Authentication/AuthenticanStore.js index 07d5ee8b..a574331b 100644 --- a/src/store/modules/Authentication/AuthenticanStore.js +++ b/src/store/modules/Authentication/AuthenticanStore.js @@ -1,6 +1,7 @@ import api from '@/store/api'; import Cookies from 'js-cookie'; import router from '@/router'; +import { EncryptStorage } from 'encrypt-storage'; const AuthenticationStore = { namespaced: true, @@ -17,6 +18,10 @@ const AuthenticationStore = { ); }, token: (state) => state.xsrfCookie, + role: () => { + const encryptStorage = new EncryptStorage('ZAaZi(P,m5+BcM|UTox5'); + return encryptStorage.getItem('storedUserrole'); + }, }, mutations: { authSuccess(state) { @@ -33,13 +38,30 @@ const AuthenticationStore = { state.xsrfCookie = undefined; state.isAuthenticatedCookie = undefined; }, + setRole(state, role) { + const encryptStorage = new EncryptStorage('ZAaZi(P,m5+BcM|UTox5'); + encryptStorage.setItem('storedUserrole', role); + }, }, actions: { - login({ commit }, { username, password }) { + login({ commit, dispatch }, { username, password }) { commit('authError', false); return api .post('/login', { data: [username, password] }) - .then(() => commit('authSuccess')) + .then(() => { + dispatch('getUser', username) + .then((response) => { + if (response.data?.RoleId) { + commit('setRole', response.data.RoleId); + } + }) + .catch((error) => { + commit('authError'); + throw new Error(error); + }); + + commit('authSuccess'); + }) .catch((error) => { commit('authError'); throw new Error(error); @@ -52,9 +74,8 @@ const AuthenticationStore = { .then(() => router.go('/login')) .catch((error) => console.log(error)); }, - checkPasswordChangeRequired(_, username) { - api - .get(`/redfish/v1/AccountService/Accounts/${username}`) + checkPasswordChangeRequired({ dispatch }, username) { + dispatch('getUser', username) .then(({ data: { PasswordChangeRequired } }) => PasswordChangeRequired) .catch((error) => console.log(error)); }, @@ -63,6 +84,9 @@ const AuthenticationStore = { state.xsrfCookie = Cookies.get('XSRF-TOKEN'); state.isAuthenticatedCookie = Cookies.get('IsAuthenticated'); }, + getUser(_, username) { + return api.get(`/redfish/v1/AccountService/Accounts/${username}`); + }, }, }; |