Skip to content

Commit

Permalink
πŸ› : fix issue with authentication guard
Browse files Browse the repository at this point in the history
  • Loading branch information
cdubuisson committed Apr 9, 2020
1 parent e83caf4 commit 579ab0e
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/main/client/app/shared/services/authentication-guard.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,28 @@ export const authenticationGuard = async (to, from, next) => {
next({ name: 'page-not-found' });
return;
}

// public page ?
if (!isPageAuthenticated(to)) {
next();
return;
}
// if no cookie, no need to go further
if (!hasCookieSession()) {
redirectToLogin(to, next);
return;
}
// reload authentication if cookie
if (hasCookieSession() && !isUserAuthenticated()) {
if (!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 {
redirectToLogin(to, next);
}
if (isUserAuthenticated()) {
redirectIfAuthorized(to, next);
} else {
// page public
next();
redirectToLogin(to, next);
}
};

0 comments on commit 579ab0e

Please sign in to comment.