diff --git a/lib/core/middleware.js b/lib/core/middleware.js index ba89a9a96..f2fb30674 100644 --- a/lib/core/middleware.js +++ b/lib/core/middleware.js @@ -16,19 +16,18 @@ Middleware.auth = function (ctx) { const { login, callback } = ctx.$auth.options.redirect const pageIsInGuestMode = routeOption(ctx.route, 'auth', 'guest') - const insideLoginPage = normalizePath(ctx.route.path) === normalizePath(login) - const insideCallbackPage = normalizePath(ctx.route.path) !== normalizePath(callback) + const insidePage = page => normalizePath(ctx.route.path) === normalizePath(page) if (ctx.$auth.$state.loggedIn) { // -- Authorized -- - if (!login || insideLoginPage || pageIsInGuestMode) { + if (!login || insidePage(login) || pageIsInGuestMode) { ctx.$auth.redirect('home') } } else { // -- Guest -- // (Those passing `callback` at runtime need to mark their callback component // with `auth: false` to avoid an unnecessary redirect from callback to login) - if (!pageIsInGuestMode && (!callback || insideCallbackPage)) { + if (!pageIsInGuestMode && (!callback || !insidePage(callback))) { ctx.$auth.redirect('login') } }