Skip to content

Commit

Permalink
fix: regression from nuxt-community#385 when callback is set to false (
Browse files Browse the repository at this point in the history
  • Loading branch information
studnitz authored and tanutsun committed Dec 18, 2019
1 parent 894b4a0 commit 0397e83
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/core/middleware.js
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 0397e83

Please sign in to comment.