Min adjust

This commit is contained in:
Juan Carlos Ruvalcaba 2021-04-21 12:48:40 -07:00
parent 4b727b21bf
commit d4a9ed07a0
2 changed files with 12 additions and 11 deletions

View File

@ -16,7 +16,7 @@ let Check = {
const router = this; const router = this;
const userData = JSON.parse(localStorage.getItem("userData")); const userData = JSON.parse(localStorage.getItem("userData"));
const userRoles = userData['userPermissions']; const userRoles = userData['userPermissions'];
//const userRoles = localStorage.getItem("roles"); //const userRoles = user.roles.value;
let currentIndex = -1; let currentIndex = -1;
for (let i = 0; i < router.routes.length; i++) { for (let i = 0; i < router.routes.length; i++) {

View File

@ -18,15 +18,13 @@ const user = createStore({
const user = response.data.user; const user = response.data.user;
const roles = response.data.roles; const roles = response.data.roles;
localStorage.setItem('token', token); localStorage.setItem('token', token);
localStorage.setItem('roles', roles);
http.defaults.headers.common['Authorization'] = token; http.defaults.headers.common['Authorization'] = token;
dispatch('auth_success', token, user); dispatch('auth_success', token, user, roles);
resolve(response); resolve(response);
}) })
.catch(err => { .catch(err => {
dispatch('auth_error'); dispatch('auth_error');
localStorage.removeItem('token'); localStorage.removeItem('token');
localStorage.removeItem('roles');
reject(err); reject(err);
}); });
}); });
@ -34,7 +32,6 @@ const user = createStore({
logOut(){ logOut(){
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
dispatch('logout'); dispatch('logout');
localStorage.removeItem('token');
localStorage.removeItem('roles'); localStorage.removeItem('roles');
http.defaults.headers.common['Authorization']; http.defaults.headers.common['Authorization'];
resolve(); resolve();
@ -46,12 +43,13 @@ const user = createStore({
state.token = ''; state.token = '';
}, },
auth_request(state){ auth_request(state){
state.status = 'loading' state.status = 'loading';
}, },
auth_success(state, token, user){ auth_success(state, token, user, roles){
state.status = 'success' state.status = 'success';
state.token = token state.token = token;
state.user = user state.user = user;
state.roles = roles;
}, },
auth_error(state){ auth_error(state){
state.status = 'error' state.status = 'error'
@ -64,7 +62,10 @@ const user = createStore({
}, },
authStatus({ state }) { authStatus({ state }) {
return state.status; return state.status;
} },
roles({ state }){
return state.roles;
},
}, },
}) })