Permalink
Browse files

fix(watcher): close #52 and undefined bug

  • Loading branch information...
breakingrobot authored and pi0 committed Feb 3, 2018
1 parent b628455 commit 2a03f2f64f7d031ad40fe7403856b00d3bfbcd18
Showing with 26 additions and 15 deletions.
  1. +7 −0 lib/module.js
  2. +5 −1 lib/templates/auth.class.js
  3. +1 −14 lib/templates/auth.middleware.js
  4. +13 −0 lib/templates/auth.utilities.js
@@ -40,6 +40,13 @@ module.exports = function (moduleOptions) {
options
})
// Utilities
this.addTemplate({
src: resolve(__dirname, './templates/auth.utilities.js'),
fileName: 'auth/auth.utilities.js',
options
})
// Class
this.addTemplate({
src: resolve(__dirname, './templates/auth.class.js'),
@@ -1,5 +1,6 @@
import Cookies from 'js-cookie'
import { parse as parseCookie } from 'cookie'
import { routeOption } from './auth.utilities'
import getProp from 'dotprop'
import Vue from 'vue'
@@ -59,7 +60,10 @@ export default class Auth {
this._loggedInWatcher =
this._loggedInWatcher ||
this.watchState('loggedIn', () => {
$auth.redirect('home')
if (routeOption(this.$route, 'auth', false)) {
return
}
this.redirect('home')
})
return this._loggedInWatcher
@@ -1,4 +1,5 @@
import Middleware from '../middleware'
import { routeOption } from "./auth.utilities";
Middleware.auth = function (ctx) {
// Disable middleware if options: { auth: false } is set on the route
@@ -20,17 +21,3 @@ Middleware.auth = function (ctx) {
ctx.app.$auth.redirect('login')
}
}
// Utility to get route option
function routeOption (route, key, value) {
return route.matched.some(m => {
// Browser
if (process.browser) {
return Object.values(m.components).some(component => component.options[key] === value)
}
// SSR
return Object.values(m.components).some(component =>
Object.values(component._Ctor).some(ctor => ctor.options && ctor.options[key] === value)
)
})
}
@@ -0,0 +1,13 @@
// Utility to get route option
export const routeOption = (route, key, value) => {
return route.matched.some(m => {
// Browser
if (process.browser) {
return Object.values(m.components).some(component => component.options[key] === value)
}
// SSR
return Object.values(m.components).some(component =>
Object.values(component._Ctor).some(ctor => ctor.options && ctor.options[key] === value)
)
})
}

0 comments on commit 2a03f2f

Please sign in to comment.