Skip to content

Commit 08d86cb

Browse files
benmccallumpi0
authored andcommitted
fix: don't redirect callback to login when using 'auth' globally (#131)
Also, if dev has disabled redirect (all or callback/login), supported according to the options documentation, don't let that affect the middleware here.
1 parent 7d17f75 commit 08d86cb

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

lib/core/middleware.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,21 @@ Middleware.auth = function (ctx) {
1414
return
1515
}
1616

17-
const { login } = ctx.app.$auth.options.redirect
17+
const { login, callback } = ctx.app.$auth.options.redirect
1818

1919
if (ctx.app.$auth.$state.loggedIn) {
2020
// -- Authorized --
21-
// Redirect to home page if inside login page
22-
if (login && ctx.route.path === login.split('?')[0]) {
21+
// Redirect to home page if inside login page (or login page disabled)
22+
if (!login || ctx.route.path === login.split('?')[0]) {
2323
ctx.app.$auth.redirect('home')
2424
}
2525
} else {
2626
// -- Guest --
27-
// Redirect to login path if not authorized
28-
ctx.app.$auth.redirect('login')
27+
// Redirect to login page if not authorized and not inside callback page
28+
// (Those passing `callback` at runtime need to mark their callback component
29+
// with `auth: false` to avoid an unnecessary redirect from callback to login)
30+
if (!callback || ctx.route.path !== callback.split('?')[0]) {
31+
ctx.app.$auth.redirect('login')
32+
}
2933
}
3034
}

0 commit comments

Comments
 (0)