Skip to content

Commit 2a03f2f

Browse files
Tony BRIETPooya Parsa
authored andcommitted
fix(watcher): close #52 and undefined bug
1 parent b628455 commit 2a03f2f

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed

lib/module.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ module.exports = function (moduleOptions) {
4040
options
4141
})
4242

43+
// Utilities
44+
this.addTemplate({
45+
src: resolve(__dirname, './templates/auth.utilities.js'),
46+
fileName: 'auth/auth.utilities.js',
47+
options
48+
})
49+
4350
// Class
4451
this.addTemplate({
4552
src: resolve(__dirname, './templates/auth.class.js'),

lib/templates/auth.class.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Cookies from 'js-cookie'
22
import { parse as parseCookie } from 'cookie'
3+
import { routeOption } from './auth.utilities'
34
import getProp from 'dotprop'
45
import Vue from 'vue'
56

@@ -59,7 +60,10 @@ export default class Auth {
5960
this._loggedInWatcher =
6061
this._loggedInWatcher ||
6162
this.watchState('loggedIn', () => {
62-
$auth.redirect('home')
63+
if (routeOption(this.$route, 'auth', false)) {
64+
return
65+
}
66+
this.redirect('home')
6367
})
6468

6569
return this._loggedInWatcher

lib/templates/auth.middleware.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Middleware from '../middleware'
2+
import { routeOption } from "./auth.utilities";
23

34
Middleware.auth = function (ctx) {
45
// Disable middleware if options: { auth: false } is set on the route
@@ -20,17 +21,3 @@ Middleware.auth = function (ctx) {
2021
ctx.app.$auth.redirect('login')
2122
}
2223
}
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-
}

lib/templates/auth.utilities.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
}

0 commit comments

Comments
 (0)