refs #5554 fix: no te tira al hacer F5
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Vicent Llopis 2023-06-29 12:15:32 +02:00
parent 3bd890c343
commit 79823605f6
2 changed files with 10 additions and 5 deletions

View File

@ -4,7 +4,8 @@ import HttpError from 'core/lib/http-error';
interceptor.$inject = ['$q', 'vnApp', '$translate'];
function interceptor($q, vnApp, $translate) {
let apiPath = 'api/';
let token;
let token = sessionStorage.getItem('vnToken')
?? localStorage.getItem('vnToken');
return {
setToken(newToken) {

View File

@ -40,7 +40,9 @@ export default class Token {
this.setStorage(localStorage, token, created, ttl);
else
this.setStorage(sessionStorage, token, created, ttl);
} catch (e) {}
} catch (err) {
console.error(err);
}
}
unset() {
@ -56,13 +58,15 @@ export default class Token {
getStorage(storage) {
this.token = storage.getItem('vnToken');
this.created = storage.getItem('vnTokenCreated');
if (!this.token) return;
const created = storage.getItem('vnTokenCreated');
this.created = created && new Date(created);
this.renewPeriod = storage.getItem('vnTokenRenewPeriod');
}
setStorage(storage, token, created, ttl) {
storage.setItem('vnToken', token);
storage.setItem('vnTokenCreated', created);
storage.setItem('vnTokenCreated', created.toJSON());
storage.setItem('vnTokenTtl', ttl);
}
@ -85,7 +89,7 @@ export default class Token {
}
checkValidity() {
if (this.checking) return;
if (this.checking || !this.created) return;
this.checking = true;
const renewPeriod = Math.min(this.ttl, this.renewPeriod) * 1000;
const maxDate = this.created.getTime() + renewPeriod;