Add automatic user token renew (#43)
This commit is contained in:
parent
6b7fe8ee47
commit
ed4d41e2d8
2 changed files with 22 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -86,6 +86,21 @@ export default {
|
|||
})
|
||||
},
|
||||
|
||||
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()
|
||||
|
|
Loading…
Reference in a new issue