From d4a9ed07a0f0017c93be6eb8c3cf3a2a0ab906e7 Mon Sep 17 00:00:00 2001 From: Juan Carlos Ruvalcaba Date: Wed, 21 Apr 2021 12:48:40 -0700 Subject: [PATCH] Min adjust --- src/js/controllers/check.js | 2 +- src/js/stores/user.js | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/js/controllers/check.js b/src/js/controllers/check.js index 0228a51..bab5666 100644 --- a/src/js/controllers/check.js +++ b/src/js/controllers/check.js @@ -16,7 +16,7 @@ let Check = { const router = this; const userData = JSON.parse(localStorage.getItem("userData")); const userRoles = userData['userPermissions']; - //const userRoles = localStorage.getItem("roles"); + //const userRoles = user.roles.value; let currentIndex = -1; for (let i = 0; i < router.routes.length; i++) { diff --git a/src/js/stores/user.js b/src/js/stores/user.js index b9cd8ef..ec47c17 100644 --- a/src/js/stores/user.js +++ b/src/js/stores/user.js @@ -18,15 +18,13 @@ const user = createStore({ const user = response.data.user; const roles = response.data.roles; localStorage.setItem('token', token); - localStorage.setItem('roles', roles); http.defaults.headers.common['Authorization'] = token; - dispatch('auth_success', token, user); + dispatch('auth_success', token, user, roles); resolve(response); }) .catch(err => { dispatch('auth_error'); localStorage.removeItem('token'); - localStorage.removeItem('roles'); reject(err); }); }); @@ -34,7 +32,6 @@ const user = createStore({ logOut(){ return new Promise((resolve, reject) => { dispatch('logout'); - localStorage.removeItem('token'); localStorage.removeItem('roles'); http.defaults.headers.common['Authorization']; resolve(); @@ -46,12 +43,13 @@ const user = createStore({ state.token = ''; }, auth_request(state){ - state.status = 'loading' + state.status = 'loading'; }, - auth_success(state, token, user){ - state.status = 'success' - state.token = token - state.user = user + auth_success(state, token, user, roles){ + state.status = 'success'; + state.token = token; + state.user = user; + state.roles = roles; }, auth_error(state){ state.status = 'error' @@ -64,7 +62,10 @@ const user = createStore({ }, authStatus({ state }) { return state.status; - } + }, + roles({ state }){ + return state.roles; + }, }, })