From 3ee609d6837327b98dcb38e182e1e9934c8185df Mon Sep 17 00:00:00 2001 From: Alexander von Studnitz Date: Sun, 23 Jun 2019 20:22:22 +0200 Subject: [PATCH] fix: don't redirect to login page if in guest mode (#385) --- lib/core/middleware.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/core/middleware.js b/lib/core/middleware.js index 68836006e..5002090b2 100644 --- a/lib/core/middleware.js +++ b/lib/core/middleware.js @@ -15,22 +15,20 @@ Middleware.auth = function (ctx) { } const { login, callback } = ctx.app.$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) if (ctx.app.$auth.$state.loggedIn) { // -- Authorized -- - // Redirect to home page if: - // - inside login page - // - login page disabled - // - options: { auth: 'guest' } is set on the page - if (!login || normalizePath(ctx.route.path) === normalizePath(login) || routeOption(ctx.route, 'auth', 'guest')) { + if (!login || insideLoginPage || pageIsInGuestMode) { ctx.app.$auth.redirect('home') } } else { // -- Guest -- - // Redirect to login page if not authorized and not inside callback page // (Those passing `callback` at runtime need to mark their callback component // with `auth: false` to avoid an unnecessary redirect from callback to login) - if (!callback || normalizePath(ctx.route.path) !== normalizePath(callback)) { + if (!pageIsInGuestMode && (!callback || insideCallbackPage)) { ctx.app.$auth.redirect('login') } }