@websanova/vue-auth
Advanced tools
Comparing version 2.7.4-beta to 2.8.0-beta
@@ -92,2 +92,3 @@ import App from './components/App.vue'; | ||
// Vue.use(VueAxios, axios); | ||
// Vue.axios.defaults.baseURL = 'https://api-demo.websanova.com/api/v1'; | ||
@@ -94,0 +95,0 @@ // Http |
@@ -45,3 +45,3 @@ module.exports = { | ||
transitionEach.call(_this, auth, function (redirect) { | ||
transitionEach.call(_this, transition, auth, function (redirect) { | ||
if (!redirect) { | ||
@@ -48,0 +48,0 @@ (next || transition.next)(); |
@@ -17,3 +17,3 @@ { | ||
"version": "2.7.4-beta", | ||
"version": "2.8.0-beta", | ||
@@ -52,3 +52,3 @@ "repository": { | ||
"@websanova/vue-auth": "2.7.4-beta", | ||
"@websanova/vue-auth": "2.8.0-beta", | ||
"axios": "0.15.3", | ||
@@ -55,0 +55,0 @@ "vue-axios": "1.2.2" |
@@ -74,3 +74,3 @@ # Vue Auth | ||
auth: AuthBearer, | ||
http: require('@websanova/vue-auth/drivers/http/axios.js'), | ||
http: require('@websanova/vue-auth/drivers/http/axios.1.x.js'), | ||
router: require('@websanova/vue-auth/drivers/router/vue-router.2.x.js') | ||
@@ -462,31 +462,14 @@ ... | ||
### transition | ||
### redirect | ||
* Fetch the state of the transition as vue-auth sees it. | ||
* Useful for doing redirects when accessing restricted routes. | ||
* Returns either an object if a redirect occurred or null. | ||
* The object is in the form `{type: <string>, from: <object>, to: <object>}` Where `type` is one of `401`, `403`, `404` and the `from` and `to` objects are just copies of the route transitions. | ||
The transitions come in five states: | ||
~~~ | ||
var redirect = this.$auth.redirect(); | ||
* **logged-out-hidden** - The user is logged out and accessing a log in required page. | ||
* **logged-out-visible** - The user is logged out and accessing a public page. | ||
* **logged-in-forbidden** - Logged in but without access to that page. | ||
* **logged-in-visible** - Logged in and accessing a page visible to any logged in user. | ||
* **logged-in-hidden** - Logged in and accessing a hidden page, for instance the login page while logged in. | ||
The function is primarily useful for setting a redirect url if trying to access a private page when logged out. | ||
In the root component (1.x example): | ||
this.$auth.login({ | ||
redirect: {name: redirect ? redirect.from.name : 'account'}, | ||
}); | ||
~~~ | ||
ready() { | ||
this.$router.beforeEach(function (transition) { | ||
if (_this.$auth.transition().from === 'logged-out-hidden') { | ||
_this.$router.go({path: '/login', query: {redirect_url: _this.$route.path}}); | ||
} | ||
else { | ||
transition.next(); | ||
} | ||
}); | ||
} | ||
~~~ | ||
@@ -830,2 +813,12 @@ ### user | ||
### v2.8.x-beta | ||
* Removed `transition` method, replaced with `redirect`. | ||
* Added `redirect` method for easy access to check for redirects from auth. | ||
### v2.7.x-beta | ||
* Added axios driver. | ||
* Addded `parseOauthState` option. | ||
### v2.6.x-beta | ||
@@ -832,0 +825,0 @@ |
@@ -9,2 +9,6 @@ var __utils = require('./lib/utils.js'), | ||
var __transitionPrev = null, | ||
__transitionThis = null, | ||
__transitionRedirecType = null; | ||
function __duckPunch(methodName, data) { | ||
@@ -31,12 +35,2 @@ var _this = this, | ||
function __setTransitionState(state) { | ||
if ( ! this.watch.transition.to) { | ||
this.watch.transition.to = state; | ||
} | ||
else { | ||
this.watch.transition.from = this.watch.transition.to; | ||
this.watch.transition.to = state; | ||
} | ||
} | ||
// Overrideable | ||
@@ -72,16 +66,21 @@ | ||
function _transitionEach(routeAuth, cb) { | ||
function _transitionEach(transition, routeAuth, cb) { | ||
routeAuth = __utils.toArray(routeAuth); | ||
__transitionPrev = __transitionThis; | ||
__transitionThis = transition; | ||
if (routeAuth && (routeAuth === true || routeAuth.constructor === Array)) { | ||
if ( ! this.check()) { | ||
__setTransitionState.call(this, 'logged-out-hidden'); | ||
__transitionRedirecType = 401; | ||
cb.call(this, this.options.authRedirect); | ||
} | ||
else if (routeAuth.constructor === Array && ! __utils.compare(routeAuth, this.watch.data[this.options.rolesVar])) { | ||
__setTransitionState.call(this, 'logged-in-forbidden'); | ||
__transitionRedirecType = 403; | ||
cb.call(this, this.options.forbiddenRedirect); | ||
} | ||
else { | ||
__setTransitionState.call(this, 'logged-in-visible'); | ||
this.watch.redirect = __transitionRedirecType ? {type: __transitionRedirecType, from: __transitionPrev, to: __transitionThis} : null; | ||
__transitionRedirecType = null; | ||
return cb(); | ||
@@ -91,7 +90,9 @@ } | ||
else if (routeAuth === false && this.check()) { | ||
__setTransitionState.call(this, 'logged-in-hidden'); | ||
__transitionRedirecType = 404; | ||
cb.call(this, this.options.notFoundRedirect); | ||
} | ||
else { | ||
__setTransitionState.call(this, 'logged-out-visible'); | ||
this.watch.redirect = __transitionRedirecType ? {type: __transitionRedirecType, from: __transitionPrev, to: __transitionThis} : null; | ||
__transitionRedirecType = null; | ||
return cb(); | ||
@@ -447,3 +448,3 @@ } | ||
loaded: false, | ||
transition: {from: null, to: null}, | ||
redirect: null, | ||
authenticated: null | ||
@@ -479,4 +480,4 @@ }; | ||
Auth.prototype.transition = function () { | ||
return this.watch.transition; | ||
Auth.prototype.redirect = function () { | ||
return this.watch.redirect; | ||
}; | ||
@@ -483,0 +484,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
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
370265
68
2700
912