diff --git a/lib/core/middleware.js b/lib/core/middleware.js index e3c1cd80d..8b5306abd 100644 --- a/lib/core/middleware.js +++ b/lib/core/middleware.js @@ -14,17 +14,21 @@ Middleware.auth = function (ctx) { return } - const { login } = ctx.app.$auth.options.redirect + const { login, callback } = ctx.app.$auth.options.redirect if (ctx.app.$auth.$state.loggedIn) { // -- Authorized -- - // Redirect to home page if inside login page - if (login && ctx.route.path === login.split('?')[0]) { + // Redirect to home page if inside login page (or login page disabled) + if (!login || ctx.route.path === login.split('?')[0]) { ctx.app.$auth.redirect('home') } } else { // -- Guest -- - // Redirect to login path if not authorized - ctx.app.$auth.redirect('login') + // 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 || ctx.route.path !== callback.split('?')[0]) { + ctx.app.$auth.redirect('login') + } } }