Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't redirect callback to login when using 'auth' globally #131

Merged
merged 2 commits into from
Apr 11, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions lib/core/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,21 @@ Middleware.auth = function (ctx) {
return
}

const { login } = ctx.app.$auth.options.redirect
const { login, callback } = ctx.app.$auth.options.redirect

if (ctx.app.$auth.$state.loggedIn) {
// -- Authorized --
// Redirect to home page if inside login page
if (login && ctx.route.path === login.split('?')[0]) {
// Redirect to home page if inside login page (or login page disabled)
if (!login || ctx.route.path === login.split('?')[0]) {
ctx.app.$auth.redirect('home')
}
} else {
// -- Guest --
// Redirect to login path if not authorized
ctx.app.$auth.redirect('login')
// 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 || ctx.route.path !== callback.split('?')[0]) {
ctx.app.$auth.redirect('login')
}
}
}