@websanova/vue-auth
Advanced tools
Comparing version 1.5.1-beta to 2.0.0-beta
@@ -91,2 +91,5 @@ import App from './components/App.vue'; | ||
Vue.use(require('../../src/index.js'), { | ||
auth: require('../../drivers/auth/bearer.js'), | ||
http: require('../../drivers/http/vue-resource.1.x.js'), | ||
router: require('../../drivers/router/vue-router.2.x.js'), | ||
rolesVar: 'role', | ||
@@ -93,0 +96,0 @@ facebookOauth2Data: { |
@@ -17,3 +17,3 @@ { | ||
"version": "1.5.1-beta", | ||
"version": "2.0.0-beta", | ||
@@ -28,3 +28,3 @@ "repository": { | ||
"dependencies": { | ||
"@websanova/vue-auth": "2.0.0-beta" | ||
}, | ||
@@ -31,0 +31,0 @@ |
@@ -28,11 +28,10 @@ # Vue Auth | ||
## Notes | ||
* There is a ton of changes in the `v1.0.0-dev` version, check the change log below. | ||
* Because the changes are quite different a `v1.0.0` version has been started, however it is still very much in dev mode. | ||
* The changes are mostly non breaking but there will be potentially a few (check change log). | ||
* The new 2.x branch features a driver centric model. This means the `router` and `http` options must **ALWAYS** set the driver to use. Please read the [Change Log](https://github.com/websanova/vue-auth#change-log) for more info. | ||
## Install | ||
## Install 2.x | ||
@@ -43,8 +42,43 @@ ~~~ | ||
The `router` and `http` drivers MUST be set. The drivers are quite small so can be replaced or overridden as necessary. | ||
**Note that the version in the driver file should denote the version it is compatible with. So `router.2x.` means it's for router 2.x.** | ||
~~~ | ||
Vue.http.options.root = 'https://api-demo.websanova.com/api/v1'; | ||
Vue.router = new VueRouter({ | ||
... | ||
}); | ||
Vue.use(require('@websanova/vue-auth'), { | ||
auth: require('@websanova/vue-auth/drivers/auth/bearer.js'), | ||
http: require('@websanova/vue-auth/drivers/http/resource.1.x.js'), | ||
router: require('@websanova/vue-auth/drivers/router/router.2.x.js'), | ||
... | ||
rolesVar: 'type' | ||
... | ||
}); | ||
~~~ | ||
## Install 1.x | ||
~~~ | ||
> sudo npm install @websanova/vue-auth | ||
~~~ | ||
~~~ | ||
Vue.http.options.root = 'https://api-demo.websanova.com/api/v1'; | ||
Vue.router = new VueRouter({ | ||
... | ||
}); | ||
Vue.use(require('@websanova/vue-auth'), { | ||
rolesVar: 'type' | ||
}); | ||
~~~ | ||
**NOTE:** If you do not set your router as `Vue.router = new VueRouter()` then you will need to feed the `router` in directly through the options. Also true for `http`. | ||
@@ -653,2 +687,17 @@ | ||
### v2.0.x-beta | ||
Vue has been in such a volatile state, especially between versions and 1 and 2. There have been many breaking changes as well as [removing vue-resource as the officially recommended package](https://medium.com/the-vue-point/retiring-vue-resource-871a82880af4) for Vue. | ||
Because of all these changes and potential breaking changes the package has been changed to a much more driver centric model for "router", "resource" and "authentication" . Due to the nature of Vue and the current eco-system with Webpack, to avoid bloat this means the drivers will need to be passed in manually. | ||
We will see some ugly `require` code when including the plugin. But as a trade off it will reduce bloat and allow the plugin to much better support different versions of Vue as well as different "router", "resource" and "authentication" modules. | ||
**To ease confusion for this driver centric model the plugin has been bumped to a 2.x version. This will also keep it in line with the current Vue 2.x version.** | ||
* Stability for extend functionality. | ||
* Driver centric model for "router", "resource" and "authentication". | ||
* The options for `router`, `http` and `auth` must be set now and will not auto bind (this is because webpack would pre load all drivers with dynamic variable). | ||
### v1.5.x-beta | ||
@@ -655,0 +704,0 @@ |
118
src/auth.js
@@ -21,3 +21,3 @@ var __utils = require('./lib/utils.js'), | ||
this.options._http.call(this, data); | ||
this.options.http._http.call(this, data); | ||
} | ||
@@ -28,3 +28,3 @@ | ||
_auth.options[methodName + 'Perform'].call(_auth, _auth.options._bindData.call(_auth, data, this)); | ||
_auth.options[methodName + 'Perform'].call(_auth, _auth.options.router._bindData.call(_auth, data, this)); | ||
} | ||
@@ -83,3 +83,3 @@ | ||
if (token) { | ||
this.options[this.options.authType + 'Auth'].request.call(this, req, token); | ||
this.options.auth.request.call(this, req, token); | ||
} | ||
@@ -93,7 +93,7 @@ | ||
if (this.options._invalidToken) { | ||
this.options._invalidToken.call(this, res); | ||
if (this.options.http._invalidToken) { | ||
this.options.http._invalidToken.call(this, res); | ||
} | ||
token = this.options[this.options.authType + 'Auth'].response.call(this, res); | ||
token = this.options.auth.response.call(this, res); | ||
@@ -150,3 +150,3 @@ if (token) { | ||
this.watch.authenticated = true; | ||
this.watch.data = this.options.parseUserData.call(this, this.options._httpData.call(this, res)); | ||
this.watch.data = this.options.parseUserData.call(this, this.options.http._httpData.call(this, res)); | ||
this.watch.loaded = true; | ||
@@ -179,3 +179,3 @@ | ||
if (data.redirect) { | ||
this.options._routerGo.call(this, data.redirect); | ||
this.options.router._routerGo.call(this, data.redirect); | ||
} | ||
@@ -201,3 +201,3 @@ } | ||
if (data.redirect && _this.options.check.call(_this)) { | ||
_this.options._routerGo.call(_this, data.redirect); | ||
_this.options.router._routerGo.call(_this, data.redirect); | ||
} | ||
@@ -231,3 +231,3 @@ } | ||
if (data.redirect) { | ||
this.options._routerGo.call(this, data.redirect); | ||
this.options.router._routerGo.call(this, data.redirect); | ||
} | ||
@@ -264,3 +264,3 @@ } | ||
if (data.redirect && _this.options.check.call(_this)) { | ||
_this.options._routerGo.call(_this, data.redirect); | ||
_this.options.router._routerGo.call(_this, data.redirect); | ||
} | ||
@@ -290,3 +290,3 @@ } | ||
if (data.redirect) { | ||
this.options._routerGo.call(this, data.redirect); | ||
this.options.router._routerGo.call(this, data.redirect); | ||
} | ||
@@ -337,3 +337,2 @@ } | ||
authType: 'bearer', | ||
rolesVar: 'roles', | ||
@@ -409,87 +408,24 @@ tokenName: 'auth-token', | ||
oauth2Perform: _oauth2Perform, | ||
// Auth drivers | ||
bearerAuth: { | ||
request: function (req, token) { | ||
this.options._setHeaders.call(this, req, {Authorization: 'Bearer ' + token}); | ||
}, | ||
response: function (res) { | ||
var token = this.options._getHeaders.call(this, res).Authorization; | ||
if (token) { | ||
token = token.split('Bearer '); | ||
return token[token.length > 1 ? 1 : 0]; | ||
} | ||
} | ||
}, | ||
basicAuth: { | ||
request: function (req, token) { | ||
this.options._setHeaders.call(this, req, {Authorization: token}); | ||
}, | ||
response: function (res) { | ||
var token = this.options._getHeaders.call(this, res).Authorization; | ||
return token; | ||
} | ||
}, | ||
deviseAuth: { | ||
tokens: ['Token-Type', 'Access-Token', 'Client', 'Uid', 'Expiry'], | ||
request: function (req, token) { | ||
var headers = {}, | ||
tokens = token.split(';'); | ||
this.options.deviseAuth.tokens.forEach(function (tokenName, index) { | ||
if (tokens[index]) { | ||
headers[tokenName] = tokens[index]; | ||
} | ||
}); | ||
this.options._setHeaders.call(this, req, headers); | ||
}, | ||
response: function (res) { | ||
var token = [], | ||
headers = this.options._getHeaders.call(this, res); | ||
if (headers['Access-Token']) { | ||
this.options.deviseAuth.tokens.forEach(function (tokenName) { | ||
if (headers[tokenName]) { | ||
token.push(headers[tokenName]); | ||
} | ||
}); | ||
return token.join(';'); | ||
} | ||
} | ||
} | ||
oauth2Perform: _oauth2Perform | ||
}; | ||
function Auth(options, driver) { | ||
var router = options.router, | ||
http = options.http; | ||
delete options.http; | ||
delete options.router; | ||
function Auth(Vue, options) { | ||
this.currentToken = null; | ||
this.options = __utils.extend(defaultOptions, [driver || {}, options || {}]); | ||
this.options.router = router; | ||
this.options.http = http; | ||
this.options = __utils.extend(defaultOptions, [options || {}]); | ||
this.options.Vue = Vue; | ||
this.watch = this.options._watch.call(this, { | ||
data: null, | ||
loaded: false, | ||
authenticated: null | ||
this.watch = new this.options.Vue({ | ||
data: function () { | ||
return { | ||
data: null, | ||
loaded: false, | ||
authenticated: null | ||
}; | ||
} | ||
}); | ||
driver._init.call(this); | ||
// Init interceptors. | ||
this.options.router._beforeEach.call(this, this.options.routerBeforeEach, this.options.transitionEach); | ||
this.options.http._interceptor.call(this, this.options.requestIntercept, this.options.responseIntercept); | ||
} | ||
@@ -496,0 +432,0 @@ |
@@ -6,9 +6,5 @@ var Auth = require('./auth.js')(); | ||
return function install(Vue, options) { | ||
var auth, | ||
driver = require('./drivers/vue.1.0.0.js') | ||
var auth = new Auth(Vue, options); | ||
driver.Vue = Vue; | ||
auth = new Auth(options, driver); | ||
var login = auth.login; | ||
@@ -15,0 +11,0 @@ var fetch = auth.fetch; |
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
345053
64
752
1
2423