refs #5554 fix: te tirava al login al hacer F5
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Vicent Llopis 2023-06-29 11:47:50 +02:00
parent ac83788f1a
commit 0b84d847b3
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']; interceptor.$inject = ['$q', 'vnApp', '$translate'];
function interceptor($q, vnApp, $translate) { function interceptor($q, vnApp, $translate) {
let apiPath = 'api/'; let apiPath = 'api/';
let token; let token = sessionStorage.getItem('vnToken')
?? localStorage.getItem('vnToken');
return { return {
setToken(newToken) { setToken(newToken) {

View File

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