Skip to content

Commit 6ec1b34

Browse files
Tony BRIETpi0
authored andcommitted
fix: prevent middleware infinite loops
1 parent 0d085eb commit 6ec1b34

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

lib/templates/auth.middleware.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,20 @@ middleware.auth = function authMiddleware ({ route, redirect, store }) {
77
const guarded = options.guarded
88

99
// Only apply the middleware to guarded routes
10-
// and exclude redirected paths to hit the middleware again.
11-
if (guarded && route.path !== '<%= options.redirect.notLoggedIn %>') {
10+
if (guarded) {
1211
// Checking if guest redirection middleware is enabled
1312
<% if (options.redirect.guest) { %>
14-
// Guest is redirected back to login page.
15-
if (!store.getters['auth/loggedIn']) {
13+
// Guest is redirected back to login page
14+
// and excluding redirected paths from hitting the middleware again.
15+
if (!store.getters['auth/loggedIn'] && route.path !== '<%= options.redirect.notLoggedIn %>') {
1616
return redirect('<%= options.redirect.notLoggedIn %>')
1717
}
1818

1919
// Checking if user redirection middleware is enabled
2020
<% } if (options.redirect.user) { %>
2121
// Guest is redirected back to login page
22-
if (store.getters['auth/loggedIn']) {
22+
// and excluding redirected paths from hitting the middleware again.
23+
if (store.getters['auth/loggedIn'] && route.path !== '<%= options.redirect.loggedIn %>') {
2324
return redirect('<%= options.redirect.loggedIn %>')
2425
}
2526
<% } %>

0 commit comments

Comments
 (0)