Skip to content
Permalink
Browse files
fix: don't redirect to login page if in guest mode (#385)
  • Loading branch information
studnitz authored and pi0 committed Jun 23, 2019
1 parent 6811ab5 commit 3ee609d6837327b98dcb38e182e1e9934c8185df
Showing 1 changed file with 5 additions and 7 deletions.
@@ -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')
}
}

0 comments on commit 3ee609d

Please sign in to comment.