Skip to content

Commit

Permalink
fix: prevent middleware infinite loops
Browse files Browse the repository at this point in the history
  • Loading branch information
breakingrobot authored and pi0 committed Jan 26, 2018
1 parent 0d085eb commit 6ec1b34
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/templates/auth.middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ middleware.auth = function authMiddleware ({ route, redirect, store }) {
const guarded = options.guarded

// Only apply the middleware to guarded routes
// and exclude redirected paths to hit the middleware again.
if (guarded && route.path !== '<%= options.redirect.notLoggedIn %>') {
if (guarded) {
// Checking if guest redirection middleware is enabled
<% if (options.redirect.guest) { %>
// Guest is redirected back to login page.
if (!store.getters['auth/loggedIn']) {
// Guest is redirected back to login page
// and excluding redirected paths from hitting the middleware again.
if (!store.getters['auth/loggedIn'] && route.path !== '<%= options.redirect.notLoggedIn %>') {
return redirect('<%= options.redirect.notLoggedIn %>')
}

// Checking if user redirection middleware is enabled
<% } if (options.redirect.user) { %>
// Guest is redirected back to login page
if (store.getters['auth/loggedIn']) {
// and excluding redirected paths from hitting the middleware again.
if (store.getters['auth/loggedIn'] && route.path !== '<%= options.redirect.loggedIn %>') {
return redirect('<%= options.redirect.loggedIn %>')
}
<% } %>
Expand Down

0 comments on commit 6ec1b34

Please sign in to comment.