File tree Expand file tree Collapse file tree 4 files changed +26
-15
lines changed Expand file tree Collapse file tree 4 files changed +26
-15
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,13 @@ module.exports = function (moduleOptions) {
40
40
options
41
41
} )
42
42
43
+ // Utilities
44
+ this . addTemplate ( {
45
+ src : resolve ( __dirname , './templates/auth.utilities.js' ) ,
46
+ fileName : 'auth/auth.utilities.js' ,
47
+ options
48
+ } )
49
+
43
50
// Class
44
51
this . addTemplate ( {
45
52
src : resolve ( __dirname , './templates/auth.class.js' ) ,
Original file line number Diff line number Diff line change 1
1
import Cookies from 'js-cookie'
2
2
import { parse as parseCookie } from 'cookie'
3
+ import { routeOption } from './auth.utilities'
3
4
import getProp from 'dotprop'
4
5
import Vue from 'vue'
5
6
@@ -59,7 +60,10 @@ export default class Auth {
59
60
this . _loggedInWatcher =
60
61
this . _loggedInWatcher ||
61
62
this . watchState ( 'loggedIn' , ( ) => {
62
- $auth . redirect ( 'home' )
63
+ if ( routeOption ( this . $route , 'auth' , false ) ) {
64
+ return
65
+ }
66
+ this . redirect ( 'home' )
63
67
} )
64
68
65
69
return this . _loggedInWatcher
Original file line number Diff line number Diff line change 1
1
import Middleware from '../middleware'
2
+ import { routeOption } from "./auth.utilities" ;
2
3
3
4
Middleware . auth = function ( ctx ) {
4
5
// Disable middleware if options: { auth: false } is set on the route
@@ -20,17 +21,3 @@ Middleware.auth = function (ctx) {
20
21
ctx . app . $auth . redirect ( 'login' )
21
22
}
22
23
}
23
-
24
- // Utility to get route option
25
- function routeOption ( route , key , value ) {
26
- return route . matched . some ( m => {
27
- // Browser
28
- if ( process . browser ) {
29
- return Object . values ( m . components ) . some ( component => component . options [ key ] === value )
30
- }
31
- // SSR
32
- return Object . values ( m . components ) . some ( component =>
33
- Object . values ( component . _Ctor ) . some ( ctor => ctor . options && ctor . options [ key ] === value )
34
- )
35
- } )
36
- }
Original file line number Diff line number Diff line change
1
+ // Utility to get route option
2
+ export const routeOption = ( route , key , value ) => {
3
+ return route . matched . some ( m => {
4
+ // Browser
5
+ if ( process . browser ) {
6
+ return Object . values ( m . components ) . some ( component => component . options [ key ] === value )
7
+ }
8
+ // SSR
9
+ return Object . values ( m . components ) . some ( component =>
10
+ Object . values ( component . _Ctor ) . some ( ctor => ctor . options && ctor . options [ key ] === value )
11
+ )
12
+ } )
13
+ }
You can’t perform that action at this time.
0 commit comments