Сообщение от shurikkan
|
Не представляю как это сделать.
|
.catch(async e => {
if (e.response.status === 401 && checkExp(this.refreshToken) && await this.refresh()) {
return this[method](path, params)
} else {
console.log(e)
return location.href = '/login'
}
})
и токены лучше проверять
const parse = token => {
const base64Url = token.split('.')[1];
const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
return JSON.parse(decodeURIComponent(atob(base64).split('')
.map(c => '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)).join('')));
}
const check = (token, type)=> {
try {
const data = parse(token)
return (new Date(data[type] * 1000)) > (new Date())
} catch (_) {
return false;
}
}
export default {
checkExp(token) {
return check(token, 'exp')
},
checkIat(token) {
return check(token, 'iat')
}
}