Skip to content

Commit

Permalink
fix: don't redirect to login page if in guest mode (#385)
Browse files Browse the repository at this point in the history
  • Loading branch information
studnitz authored and pi0 committed Jun 23, 2019
1 parent 6811ab5 commit 3ee609d
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions lib/core/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
}
Expand Down

0 comments on commit 3ee609d

Please sign in to comment.