Skip to content
Permalink
Browse files
fix: regression from #385 when callback is set to false (#391)
  • Loading branch information
studnitz authored and pi0 committed Jun 24, 2019
1 parent 9cf304f commit 46056814c798ed6e1d35617dcd0ade9c2f0d4b43
Showing 1 changed file with 3 additions and 4 deletions.
@@ -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')
}
}

0 comments on commit 4605681

Please sign in to comment.