@websanova/vue-auth
Version:
A simple light-weight authentication library for Vue.js
48 lines (42 loc) • 1.61 kB
JavaScript
/*!
* @websanova/vue-auth v4.2.1
* https://websanova.com/docs/vue-auth
* Released under the MIT License.
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.VueAuth = factory());
}(this, (function () { 'use strict';
var devise = {
tokens: ['Token-Type', 'Access-Token', 'Client', 'Uid', 'Expiry', 'token-type', 'access-token', 'client', 'uid', 'expiry'],
request: function (req, token) {
var headers = {},
tokens = token.split('|');
var auth = this.drivers.deviseAuth || this.drivers.auth;
auth.tokens.forEach(function (tokenName, index) {
if (tokens[index]) {
headers[tokenName] = tokens[index];
}
});
this.drivers.http.setHeaders.call(this, req, headers);
},
response: function (res) {
var token = [],
headers = this.drivers.http.getHeaders.call(this, res);
if (headers['access-token'] || headers['Access-Token']) {
var auth = this.drivers.deviseAuth || this.drivers.auth;
auth.tokens.forEach(function (tokenName) {
if (headers[tokenName]) {
token.push(headers[tokenName]);
}
});
// 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('|');
}
}
}
};
return devise;
})));