vue-jwt-auth
Advanced tools
Comparing version 0.6.1 to 0.7.0
@@ -19,3 +19,3 @@ { | ||
}, | ||
"version": "0.6.1" | ||
"version": "0.7.0" | ||
} |
module.exports = (function () { | ||
var _tokenRefreshTimeout = null; | ||
// Default | ||
@@ -105,4 +107,12 @@ | ||
function _refreshToken() { | ||
var _this = this; | ||
if (_getToken.call(this)) { | ||
this.$http.get(this.getOption('tokenUrl')); | ||
clearTimeout(_tokenRefreshTimeout); | ||
_tokenRefreshTimeout = setTimeout(function () { | ||
_refreshToken.call(_this); | ||
}, this.getOption('tokenTimeout')); | ||
} | ||
@@ -221,3 +231,4 @@ } | ||
tokenName : 'jwt-auth-token', | ||
tokenTimeout : 3000 * 1000, // 50 minutes (in milliseconds). | ||
cookieDomain : _cookieDomain, | ||
@@ -246,37 +257,2 @@ userData : _userData, | ||
created: function () { | ||
var _this = this; | ||
this.$http.interceptors.push({ | ||
// Send auth token on each request. | ||
request: function (req) { | ||
var token = _getToken.call(_this); | ||
if (token) { | ||
if (_this.getOption('authType') === 'bearer') { | ||
req.headers.Authorization = 'Bearer: ' + token; | ||
} | ||
} | ||
return req; | ||
}, | ||
// Reset auth token if provided in response. | ||
response: function (res) { | ||
var authorization = res.headers('authorization'); | ||
if (authorization) { | ||
authorization = authorization.split(' '); | ||
if (authorization[1]) { | ||
_setToken.call(this, authorization[1]); | ||
} | ||
} | ||
return res; | ||
} | ||
}); | ||
}, | ||
methods: { | ||
@@ -437,3 +413,3 @@ | ||
// // Setup before each route change check. | ||
// Setup before each route change check. | ||
(Vue.router || router).beforeEach(function (transition) { | ||
@@ -445,4 +421,36 @@ | ||
}); | ||
}); | ||
}); | ||
// Set interceptors. | ||
Vue.http.interceptors.push({ | ||
// Send auth token on each request. | ||
request: function (req) { | ||
var token = _getToken.call(auth); | ||
if (token) { | ||
if (auth.getOption('authType') === 'bearer') { | ||
req.headers.Authorization = 'Bearer: ' + token; | ||
} | ||
} | ||
return req; | ||
}, | ||
// Reset auth token if provided in response. | ||
response: function (res) { | ||
var authorization = res.headers('authorization'); | ||
if (authorization) { | ||
authorization = authorization.split(' '); | ||
if (authorization[1]) { | ||
_setToken.call(auth, authorization[1]); | ||
} | ||
} | ||
return res; | ||
} | ||
}); | ||
} | ||
})(); |
22525
7
341