@websanova/vue-auth
Advanced tools
Comparing version 1.2.0-beta to 1.3.0-beta
@@ -46,3 +46,26 @@ import App from './components/App.vue'; | ||
name: 'admin', | ||
component: require('./components/pages/Admin.vue') | ||
component: require('./components/pages/Admin.vue'), | ||
subRoutes: { | ||
'/products': { | ||
name: 'admin-products', | ||
component: require('./components/pages/admin/Products.vue'), | ||
subRoutes: { | ||
'/:product_id': { | ||
name: 'admin-product', | ||
component: require('./components/pages/admin/Product.vue'), | ||
subRoutes: { | ||
'/info': { | ||
auth: undefined, | ||
name: 'admin-product-info', | ||
component: require('./components/pages/admin/ProductInfo.vue'), | ||
}, | ||
'/media': { | ||
name: 'admin-product-media', | ||
component: require('./components/pages/admin/ProductMedia.vue'), | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
@@ -49,0 +72,0 @@ '/users': { |
@@ -44,3 +44,23 @@ import App from './components/App.vue'; | ||
component: require('./components/pages/Admin.vue'), | ||
meta: {auth: 'admin'} | ||
meta: {auth: 'admin'}, | ||
children: [{ | ||
path: 'products', | ||
name: 'admin-products', | ||
component: require('./components/pages/admin/Products.vue'), | ||
children: [{ | ||
path: ':product_id', | ||
name: 'admin-product', | ||
component: require('./components/pages/admin/Product.vue'), | ||
children: [{ | ||
path: 'info', | ||
name: 'admin-product-info', | ||
component: require('./components/pages/admin/ProductInfo.vue'), | ||
meta: {auth: undefined} | ||
}, { | ||
path: 'media', | ||
name: 'admin-product-media', | ||
component: require('./components/pages/admin/ProductMedia.vue') | ||
}] | ||
}] | ||
}] | ||
}, { | ||
@@ -47,0 +67,0 @@ path: '/users', |
{ | ||
"main": "src/index.js", | ||
"dependencies": { | ||
"@websanova/vue-auth": "1.2.0-beta" | ||
}, | ||
"devDependencies": { | ||
@@ -9,0 +4,0 @@ "babel-core": "6.16.0", |
@@ -17,3 +17,3 @@ { | ||
"version": "1.2.0-beta", | ||
"version": "1.3.0-beta", | ||
@@ -28,3 +28,3 @@ "repository": { | ||
"dependencies": { | ||
"@websanova/vue-auth": "1.2.0-beta" | ||
}, | ||
@@ -31,0 +31,0 @@ |
@@ -70,5 +70,9 @@ # Vue Auth | ||
> sudo npm install | ||
> sudo npm run demo | ||
> sudo npm run 1.x.demo | ||
> sudo npm run 2.x.demo | ||
~~~ | ||
Note: For Vue 2 demo there is a separate package.json. Unfortunately there is no really great way to run both at the same time. | ||
If a different path is required it must be set in the `demo/app.js` file. | ||
@@ -88,2 +92,4 @@ | ||
**Vue 1.x** | ||
~~~ | ||
@@ -117,4 +123,34 @@ Vue.router.map({ | ||
**Vue 1.x** | ||
~~~ | ||
Vue.router = new VueRouter({ | ||
routes: [{ | ||
path: '/admin', | ||
meta: {auth: 'admin'}, | ||
component: require('./Admin') | ||
}, { | ||
path: '/manage', | ||
meta: {auth: ['admin', 'manager']}, | ||
component: require('./Manage') | ||
}, { | ||
path: '/account', | ||
meta: {auth: true}, | ||
component: require('./Account') | ||
}, { | ||
path: '/private', | ||
meta: {auth: [{"people": "administrator", "people": "superadmin"}]}, | ||
component: require('./Account') | ||
}, { | ||
path: '/login', | ||
meta: {auth: false}, | ||
component: require('./Login') | ||
}, { | ||
path: '/contact', | ||
component: require('./Contact') | ||
}] | ||
}); | ||
~~~ | ||
## Routes | ||
@@ -379,3 +415,3 @@ | ||
### token: `[{name: 'Authorization', authType: 'bearer', foundIn: 'header'}, {name: 'token', authType: 'bearer', foundIn: 'response'}]` | ||
### token: `[{request: 'Authorization', response: 'Authorization', authType: 'bearer', foundIn: 'header'}, {request: 'token', response: 'token', authType: 'bearer', foundIn: 'response'}]` | ||
@@ -499,2 +535,13 @@ * Set of method for fetching the token from the response. It will attempt each until a token is found and stop there. | ||
### v1.3.x-beta | ||
* Add support for sub route `auth` matching via parent in Vue 2. | ||
### v1.2.x-beta | ||
* Token parameters now accept `request` and `response` params instead of `name`. | ||
* Support for Vue 2 `auth` in `meta` of route. | ||
### v1.0.x-dev | ||
@@ -501,0 +548,0 @@ |
@@ -12,5 +12,5 @@ var __utils = require('./lib/utils.js'), | ||
success = data.success; | ||
data = __utils.extend(this.options[methodName + 'Data'], [data]); | ||
data.success = function (res) { | ||
@@ -30,3 +30,3 @@ data.success = success; | ||
} | ||
// Overrideable | ||
@@ -57,3 +57,3 @@ | ||
function _transitionEach(routeAuth, next) { | ||
function _transitionEach(routeAuth, cb) { | ||
routeAuth = __utils.toArray(routeAuth); | ||
@@ -63,16 +63,16 @@ | ||
if ( ! this.check()) { | ||
this.options._routerReplace.call(this, this.options.authRedirect); | ||
cb.call(this, this.options.authRedirect); | ||
} | ||
else if (routeAuth.constructor === Array && ! __utils.compare(routeAuth, this.watch.data[this.options.rolesVar])) { | ||
this.options._routerReplace.call(this, this.options.forbiddenRedirect); | ||
cb.call(this, this.options.forbiddenRedirect); | ||
} | ||
else { | ||
return next(); | ||
return cb(); | ||
} | ||
} | ||
else if (routeAuth === false && this.check()) { | ||
this.options._routerReplace.call(this, this.options.notFoundRedirect); | ||
cb.call(this, this.options.notFoundRedirect); | ||
} | ||
else { | ||
return next(); | ||
return cb(); | ||
} | ||
@@ -90,3 +90,3 @@ } | ||
} | ||
function _responseIntercept(res) { | ||
@@ -219,3 +219,3 @@ var i, ii, | ||
data = __utils.extend(this.options.logoutData, [data || {}]); | ||
if (data.makeRequest) { | ||
@@ -281,3 +281,3 @@ __duckPunch.call(this, 'logout', data); | ||
data = __utils.extend(this.options.logoutOtherData, [data || {}]); | ||
if (data.makeRequest) { | ||
@@ -379,3 +379,3 @@ __duckPunch.call(this, 'logoutOther', data); | ||
googleData: {url: 'auth/google', method: 'POST', redirect: '/'}, | ||
facebookOauth2Data: { | ||
@@ -401,3 +401,3 @@ url: 'https://www.facebook.com/v2.5/dialog/oauth', | ||
check: _check, | ||
transitionEach: _transitionEach, | ||
@@ -418,3 +418,3 @@ routerBeforeEach: _routerBeforeEach, | ||
logoutProcess: _logoutProcess, | ||
fetchPerform: _fetchPerform, | ||
@@ -428,3 +428,3 @@ fetchProcess: _fetchProcess, | ||
loginOtherProcess: _loginOtherProcess, | ||
logoutOtherPerform: _logoutOtherPerform, | ||
@@ -436,3 +436,3 @@ logoutOtherProcess: _logoutOtherProcess, | ||
// Auth drivers | ||
bearerAuth: { | ||
@@ -491,3 +491,3 @@ request: function (req, token) { | ||
}; | ||
Auth.prototype.user = function (data) { | ||
@@ -552,10 +552,10 @@ if (data) { | ||
Auth.prototype.logoutOther = function (data) { | ||
__bindContext.call(this, 'logoutOther', data); | ||
__bindContext.call(this, 'logoutOther', data); | ||
}; | ||
Auth.prototype.oauth2 = function (data) { | ||
__bindContext.call(this, 'oauth2', data); | ||
__bindContext.call(this, 'oauth2', data); | ||
} | ||
return Auth; | ||
}; | ||
}; |
@@ -78,3 +78,30 @@ module.exports = { | ||
routerBeforeEach.call(_this, function () { | ||
transitionEach.call(_this, transition.meta ? transition.meta.auth : (transition.to || {}).auth, function () { (next || transition.next)(); }); | ||
var auth; | ||
if (transition.to) { | ||
auth = transition.to.auth; | ||
} else { | ||
var authRoutes = transition.matched.filter(function (route) { | ||
return route.meta.hasOwnProperty('auth'); | ||
}); | ||
// matches the nested route, the last one in the list | ||
if (authRoutes.length) { | ||
auth = authRoutes[authRoutes.length - 1].meta.auth; | ||
} | ||
} | ||
transitionEach.call(_this, auth, function (redirect) { | ||
if (!redirect) { | ||
(next || transition.next)(); | ||
return; | ||
} | ||
// router v2.x | ||
if (next) { | ||
next(redirect); | ||
} else { | ||
this.options._routerReplace.call(this, redirect); | ||
} | ||
}); | ||
}); | ||
@@ -91,3 +118,5 @@ }) | ||
_routerReplace: function (data) { | ||
this.options.router.replace(data); | ||
var router = this.options.router; | ||
router.replace.call(router, data); | ||
}, | ||
@@ -94,0 +123,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
366383
0
57
3229
573
- Removed@websanova/vue-auth@1.2.0-beta