Skip to content
Permalink
Browse files
fix(watcher): close #52 and undefined bug
  • Loading branch information
breakingrobot authored and Pooya Parsa committed Feb 3, 2018
1 parent b628455 commit 2a03f2f64f7d031ad40fe7403856b00d3bfbcd18
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
@@ -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.