Skip to content

Commit

Permalink
fix: regression from #385 when callback is set to false (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
studnitz authored and pi0 committed Jun 24, 2019
1 parent 9cf304f commit 4605681
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/core/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
}
Expand Down

0 comments on commit 4605681

Please sign in to comment.