refs #5554 fix: te tirava al login al hacer F5
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
ac83788f1a
commit
0b84d847b3
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue