@websanova/vue-auth
Advanced tools
Comparing version 2.18.3-beta to 2.19.0-beta
{ | ||
"dependencies": { | ||
"@websanova/vue-auth": "2.18.3-beta" | ||
"@websanova/vue-auth": "2.19.0-beta" | ||
}, | ||
@@ -5,0 +5,0 @@ |
{ | ||
"dependencies": { | ||
"@websanova/vue-auth": "2.18.3-beta", | ||
"@websanova/vue-auth": "2.19.0-beta", | ||
"axios": "0.16.2", | ||
@@ -5,0 +5,0 @@ "vue-axios": "2.0.2" |
@@ -48,3 +48,3 @@ import App from './components/App.vue'; | ||
component: require('./components/pages/Admin.vue'), | ||
meta: {auth: {roles: 'admin', redirect: {name: 'login'}, forbiddenRedirect: '/403'}}, | ||
meta: {auth: {roles: 'admin', redirect: {name: 'default'}, forbiddenRedirect: '/403'}}, | ||
children: [{ | ||
@@ -98,10 +98,2 @@ path: 'products', | ||
Vue.http.interceptors.push(function(request, next) { | ||
next(function (res) { | ||
if (res.status === 401) { | ||
Vue.auth.logout(); | ||
} | ||
}); | ||
}); | ||
// Vue Auth | ||
@@ -108,0 +100,0 @@ Vue.use(require('../../../src/index.js'), { |
{ | ||
"dependencies": { | ||
"nuxt": "1.0.0-rc3", | ||
"@websanova/vue-auth": "2.18.3-beta", | ||
"@websanova/vue-auth": "2.19.0-beta", | ||
"vue-resource": "1.3.4", | ||
@@ -6,0 +6,0 @@ "axios": "0.16.2", |
@@ -47,3 +47,3 @@ { | ||
"dependencies": { | ||
"@websanova/vue-auth": "2.18.3-beta", | ||
"@websanova/vue-auth": "2.19.0-beta", | ||
"axios": "^0.16.2", | ||
@@ -50,0 +50,0 @@ "compression": "^1.6.2", |
# Change Log | ||
### v2.19.x-beta | ||
* Update to handle failed token redirects internally (rather than requiring additional interceptors). | ||
### v2.18.x-beta | ||
@@ -4,0 +8,0 @@ |
@@ -25,3 +25,3 @@ # FAQ | ||
The token can be supplied anywhere in your app response. The provided [auth](https://github.com/websanova/vue-auth/tree/master/drivers/auth) drivers are common methods for authenticating users in single page apps. Simply view any of the [auth]https://github.com/websanova/vue-auth/tree/master/drivers/auth) drivers as a guide to write your own custom driver. | ||
The token can be supplied anywhere in your app response. The provided [auth](https://github.com/websanova/vue-auth/tree/master/drivers/auth) drivers are common methods for authenticating users in single page apps. Simply view any of the [auth](https://github.com/websanova/vue-auth/tree/master/drivers/auth) drivers as a guide to write your own custom driver. | ||
@@ -44,2 +44,2 @@ | ||
Note that `vue-auth` simply forwards all the arguments into whatever http plugin/module you are using. So for `vue-axios` it will be a `data` parameter and for `vue-resource` it's a `body` parameter. | ||
Note that `vue-auth` simply forwards all the arguments into whatever http plugin/module you are using. So for `vue-axios` it will be a `data` parameter and for `vue-resource` it's a `body` parameter. |
@@ -162,3 +162,3 @@ # Step By Step Guide | ||
* A common issue is the Axios error response. When doing `console.log(error)` it will output the error string. Use `console.log(error.resposne)` instead. | ||
* A common issue is the Axios error response. When doing `console.log(error)` it will output the error string. Use `console.log(error.response)` instead. | ||
@@ -165,0 +165,0 @@ * When making requests (typically) it should be a relative path without a `/` in front. For example `auth/user`, `products`, `items/123`. |
@@ -31,5 +31,8 @@ module.exports = { | ||
return token.join(';'); | ||
// Check if access-token more recent than last one | ||
if (!this.token() || parseInt(token[4], 10) >= parseInt(this.token().split(';')[4], 10)) { | ||
return token.join(';'); | ||
} | ||
} | ||
} | ||
}; |
@@ -36,7 +36,5 @@ module.exports = { | ||
_invalidToken: function (res) { | ||
// Removed - should be handled by the app as there are too many considerations here for checking this. | ||
// if (res.status === 401) { | ||
// this.options.logoutProcess.call(this, res, {redirect: this.options.authRedirect}); | ||
// } | ||
if (res.status === 401) { | ||
return true; | ||
} | ||
}, | ||
@@ -43,0 +41,0 @@ |
@@ -21,8 +21,6 @@ module.exports = { | ||
_invalidToken: function (res) { | ||
// Removed - should be handled by the app as there are too many considerations here for checking this. | ||
// if (res.status === 401) { | ||
// this.options.logoutProcess.call(this, res, {redirect: this.options.authRedirect}); | ||
// } | ||
_invalidToken: function (res, transition) { | ||
if (res.status === 401) { | ||
return true; | ||
} | ||
}, | ||
@@ -29,0 +27,0 @@ |
@@ -29,18 +29,7 @@ module.exports = { | ||
this.options.Vue.router.beforeEach(function (transition, location, next) { | ||
_this.options.setTransitions.call(this, transition); | ||
routerBeforeEach.call(_this, function () { | ||
var auth; | ||
var auth = _this.options.getAuthMeta(transition); | ||
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, transition, auth, function (redirect) { | ||
@@ -47,0 +36,0 @@ if (!redirect) { |
@@ -17,3 +17,3 @@ { | ||
"version": "2.18.3-beta", | ||
"version": "2.19.0-beta", | ||
@@ -20,0 +20,0 @@ "repository": { |
@@ -91,5 +91,2 @@ var __utils = require('./lib/utils.js'), | ||
routeAuth = __utils.toArray((routeAuth || '').roles || routeAuth); | ||
__transitionPrev = __transitionThis; | ||
__transitionThis = transition; | ||
@@ -152,5 +149,3 @@ if (routeAuth && (routeAuth === true || routeAuth.constructor === Array)) { | ||
if (this.options.http._invalidToken) { | ||
this.options.http._invalidToken.call(this, res); | ||
} | ||
_processInvalidToken.call(this, res, __transitionThis); | ||
@@ -198,2 +193,50 @@ token = this.options.auth.response.call(this, res); | ||
function _getAuthMeta (transition) { | ||
var auth, | ||
authRoutes; | ||
if (transition.to) { | ||
auth = transition.to.auth; | ||
} else { | ||
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; | ||
} | ||
} | ||
return auth; | ||
} | ||
function _setTransitions (transition) { | ||
__transitionPrev = __transitionThis; | ||
__transitionThis = transition; | ||
} | ||
function _processInvalidToken(res, transition) { | ||
var auth, | ||
redirect = transition.path; | ||
if (!this.options.http._invalidToken) { | ||
return; | ||
} | ||
if (!this.options.http._invalidToken.call(this, res)) { | ||
return; | ||
} | ||
if (transition) { | ||
auth = this.options.getAuthMeta(transition); | ||
} | ||
if (auth) { | ||
redirect = auth.redirect || this.options.authRedirect; | ||
} | ||
this.options.logoutProcess.call(this, res, {redirect: redirect}); | ||
} | ||
function _fetchPerform(data) { | ||
@@ -450,2 +493,4 @@ var _this = this, | ||
checkAuthenticated: _checkAuthenticated, | ||
getAuthMeta: _getAuthMeta, | ||
setTransitions: _setTransitions, | ||
@@ -533,9 +578,9 @@ readyCallback: null, | ||
// Set refresh interval. | ||
if (this.options.refreshData.interval && this.options.refreshData.interval > 0) { | ||
setInterval(function () { | ||
if (this.options.refreshData.enabled && !this.options.tokenExpired.call(this)) { | ||
this.options.refreshPerform.call(this, {}); | ||
} | ||
}.bind(this), this.options.refreshData.interval * 1000 * 60); // In minutes. | ||
} | ||
// if (this.options.refreshData.interval && this.options.refreshData.interval > 0) { | ||
// setInterval(function () { | ||
// if (this.options.refreshData.enabled && !this.options.tokenExpired.call(this)) { | ||
// this.options.refreshPerform.call(this, {}); | ||
// } | ||
// }.bind(this), this.options.refreshData.interval * 1000 * 60); // In minutes. | ||
// } | ||
@@ -542,0 +587,0 @@ // Init interceptors. |
Sorry, the diff of this file is not supported yet
766516
2455
146