File tree Expand file tree Collapse file tree 1 file changed +5
-7
lines changed Expand file tree Collapse file tree 1 file changed +5
-7
lines changed Original file line number Diff line number Diff line change @@ -15,22 +15,20 @@ Middleware.auth = function (ctx) {
15
15
}
16
16
17
17
const { login, callback } = ctx . app . $auth . options . redirect
18
+ const pageIsInGuestMode = routeOption ( ctx . route , 'auth' , 'guest' )
19
+ const insideLoginPage = normalizePath ( ctx . route . path ) === normalizePath ( login )
20
+ const insideCallbackPage = normalizePath ( ctx . route . path ) !== normalizePath ( callback )
18
21
19
22
if ( ctx . app . $auth . $state . loggedIn ) {
20
23
// -- Authorized --
21
- // Redirect to home page if:
22
- // - inside login page
23
- // - login page disabled
24
- // - options: { auth: 'guest' } is set on the page
25
- if ( ! login || normalizePath ( ctx . route . path ) === normalizePath ( login ) || routeOption ( ctx . route , 'auth' , 'guest' ) ) {
24
+ if ( ! login || insideLoginPage || pageIsInGuestMode ) {
26
25
ctx . app . $auth . redirect ( 'home' )
27
26
}
28
27
} else {
29
28
// -- Guest --
30
- // Redirect to login page if not authorized and not inside callback page
31
29
// (Those passing `callback` at runtime need to mark their callback component
32
30
// with `auth: false` to avoid an unnecessary redirect from callback to login)
33
- if ( ! callback || normalizePath ( ctx . route . path ) !== normalizePath ( callback ) ) {
31
+ if ( ! pageIsInGuestMode && ( ! callback || insideCallbackPage ) ) {
34
32
ctx . app . $auth . redirect ( 'login' )
35
33
}
36
34
}
You can’t perform that action at this time.
0 commit comments