Skip to content

Commit 3ee609d

Browse files
studnitzpi0
authored andcommitted
fix: don't redirect to login page if in guest mode (#385)
1 parent 6811ab5 commit 3ee609d

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

lib/core/middleware.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,20 @@ Middleware.auth = function (ctx) {
1515
}
1616

1717
const { login, callback } = ctx.app.$auth.options.redirect
18+
const pageIsInGuestMode = routeOption(ctx.route, 'auth', 'guest')
19+
const insideLoginPage = normalizePath(ctx.route.path) === normalizePath(login)
20+
const insideCallbackPage = normalizePath(ctx.route.path) !== normalizePath(callback)
1821

1922
if (ctx.app.$auth.$state.loggedIn) {
2023
// -- Authorized --
21-
// Redirect to home page if:
22-
// - inside login page
23-
// - login page disabled
24-
// - options: { auth: 'guest' } is set on the page
25-
if (!login || normalizePath(ctx.route.path) === normalizePath(login) || routeOption(ctx.route, 'auth', 'guest')) {
24+
if (!login || insideLoginPage || pageIsInGuestMode) {
2625
ctx.app.$auth.redirect('home')
2726
}
2827
} else {
2928
// -- Guest --
30-
// Redirect to login page if not authorized and not inside callback page
3129
// (Those passing `callback` at runtime need to mark their callback component
3230
// with `auth: false` to avoid an unnecessary redirect from callback to login)
33-
if (!callback || normalizePath(ctx.route.path) !== normalizePath(callback)) {
31+
if (!pageIsInGuestMode && (!callback || insideCallbackPage)) {
3432
ctx.app.$auth.redirect('login')
3533
}
3634
}

0 commit comments

Comments
 (0)