Skip to content

Commit

Permalink
πŸ› : fix issue on page authorities management
Browse files Browse the repository at this point in the history
  • Loading branch information
cdubuisson committed Apr 9, 2020
1 parent c878d0a commit f3e063f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
3 changes: 3 additions & 0 deletions src/main/client/app/pages/stacks/stacks-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@ const stacksRoutes = [
path: 'add',
name: 'stack-creation',
component: () => import(/* webpackChunkName: "chunk-stacks" */ '@/pages/stacks/stack-creation.vue'),
meta: { authorities: ['ROLE_USER'] },
},
{
path: 'edit',
name: 'stack-edition',
component: () => import(/* webpackChunkName: "chunk-stacks" */ '@/pages/stacks/stack-edition.vue'),
meta: { authorities: ['ROLE_USER'] },
},
{
path: 'jobs/:jobId',
name: 'stack_job',
component: () => import(/* webpackChunkName: "chunk-stacks" */ '@/pages/stacks/stack-job.vue'),
meta: { authorities: ['ROLE_USER'] },
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
data: () => ({
entries: [
{
route: 'dashboard', icon: 'tachometer-alt', class: 'yellow_color', title: 'Dashboard',
route: 'dashboard', icon: 'tachometer-alt', class: 'yellow_color', title: 'Dashboard', roles: ['ROLE_USER'],
},
{
route: 'modules', icon: 'object-group', class: 'blue1_color', title: 'Modules',
route: 'modules', icon: 'object-group', class: 'blue1_color', title: 'Modules', roles: ['ROLE_USER'],
},
{
route: 'stacks', icon: 'layer-group', class: 'blue2_color', title: 'Stacks',
route: 'stacks', icon: 'layer-group', class: 'blue2_color', title: 'Stacks', roles: ['ROLE_USER'],
},
{
route: 'settings', icon: 'cog', class: 'yellow_color', title: 'Settings', roles: ['ROLE_ADMIN'],
Expand Down
19 changes: 10 additions & 9 deletions src/main/client/app/shared/services/authentication-guard.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,24 @@ export const authenticationGuard = async (to, from, next) => {
return;
}

// reload authentication if cookie
if (hasCookieSession() && !isUserAuthenticated()) {
try {
await store.dispatch('session/authenticated');
} catch (e) {
// in case of expired or invalid cookie
}
}

// check page
if (isPageAuthenticated(to)) {
if (isUserAuthenticated()) {
redirectIfAuthorized(to, next);
} else if (hasCookieSession()) {
try {
await store.dispatch('session/authenticated');
redirectIfAuthorized(to, next);
} catch (e) {
// in case of expired or invalid cookie
redirectToLogin(to, next);
}
} else {
redirectToLogin(to, next);
}
} else {
// page public
next();
}

};
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const sessionState = {

const sessionGetters = {
hasAuthorities: (state) => (authorities) => {
if (!state.authenticated || !state.authorities) return false;
if (!authorities) return true;
if (!state.authenticated || !state.authorities) return false;
let authoritiesToCheck = authorities;
if (typeof authorities === 'string') {
authoritiesToCheck = [authorities];
Expand Down

0 comments on commit f3e063f

Please # to comment.