diff --git a/src/App.vue b/src/App.vue index e267fec3ad..cf7bf96b1a 100644 --- a/src/App.vue +++ b/src/App.vue @@ -248,6 +248,11 @@ window.location.reload(); } ); + + // Schedule a token renew every 60 minutes + setTimeout(() => { + auth.renewToken() + }, 1000 * 60 * 60) }, watch: { // call the method again if the route changes diff --git a/src/auth/index.js b/src/auth/index.js index 876ef6bc54..1f6d9904c4 100644 --- a/src/auth/index.js +++ b/src/auth/index.js @@ -76,16 +76,31 @@ export default { }, linkShareAuth(hash) { - return HTTP.post('/shares/'+hash+'/auth') + return HTTP.post('/shares/' + hash + '/auth') .then(r => { localStorage.setItem('token', r.data.token) this.getUserInfos() return Promise.resolve(r.data) - }).catch(e => { + }).catch(e => { return Promise.reject(e) }) }, + renewToken() { + HTTP.post('user/token', null, { + headers: { + Authorization: 'Bearer ' + localStorage.getItem('token'), + } + }) + .then(r => { + localStorage.setItem('token', r.data.token) + }) + .catch(e => { + // eslint-disable-next-line + console.log('Error renewing token: ', e) + }) + }, + checkAuth() { let jwt = localStorage.getItem('token') this.getUserInfos()