Fix auth not persisting on reload (#360)
This commit is contained in:
parent
8c4348b9f8
commit
1ef9f7df6d
@ -159,18 +159,18 @@ export default class AuthService {
|
|||||||
private async checkFreshness() {
|
private async checkFreshness() {
|
||||||
window.clearTimeout(this.timerId);
|
window.clearTimeout(this.timerId);
|
||||||
|
|
||||||
console.debug("checkFreshness authState:", this._authState);
|
// console.debug("checkFreshness authState:", this._authState);
|
||||||
|
|
||||||
if (!this._authState) return;
|
if (!this._authState) return;
|
||||||
const paddedNow = Date.now() + FRESHNESS_TIMER_INTERVAL;
|
const paddedNow = Date.now() + FRESHNESS_TIMER_INTERVAL - 500; // tweak padding to account for API fetch time
|
||||||
|
|
||||||
if (this._authState.sessionExpiresAt > paddedNow) {
|
if (this._authState.sessionExpiresAt > paddedNow) {
|
||||||
if (this._authState.tokenExpiresAt > paddedNow) {
|
if (this._authState.tokenExpiresAt > paddedNow) {
|
||||||
console.debug(
|
// console.debug(
|
||||||
"fresh! restart timer tokenExpiresAt:",
|
// "fresh! restart timer tokenExpiresAt:",
|
||||||
new Date(this._authState.tokenExpiresAt)
|
// new Date(this._authState.tokenExpiresAt)
|
||||||
);
|
// );
|
||||||
console.debug("fresh! restart timer paddedNow:", new Date(paddedNow));
|
// console.debug("fresh! restart timer paddedNow:", new Date(paddedNow));
|
||||||
// Restart timer
|
// Restart timer
|
||||||
this.timerId = window.setTimeout(() => {
|
this.timerId = window.setTimeout(() => {
|
||||||
this.checkFreshness();
|
this.checkFreshness();
|
||||||
@ -180,15 +180,16 @@ export default class AuthService {
|
|||||||
const auth = await this.refresh();
|
const auth = await this.refresh();
|
||||||
this._authState.headers = auth.headers;
|
this._authState.headers = auth.headers;
|
||||||
this._authState.tokenExpiresAt = auth.tokenExpiresAt;
|
this._authState.tokenExpiresAt = auth.tokenExpiresAt;
|
||||||
|
this.persist(this._authState);
|
||||||
|
|
||||||
console.debug(
|
// console.debug(
|
||||||
"refreshed. restart timer tokenExpiresAt:",
|
// "refreshed. restart timer tokenExpiresAt:",
|
||||||
new Date(this._authState.tokenExpiresAt)
|
// new Date(this._authState.tokenExpiresAt)
|
||||||
);
|
// );
|
||||||
console.debug(
|
// console.debug(
|
||||||
"refreshed. restart timer paddedNow:",
|
// "refreshed. restart timer paddedNow:",
|
||||||
new Date(paddedNow)
|
// new Date(paddedNow)
|
||||||
);
|
// );
|
||||||
|
|
||||||
// Restart timer
|
// Restart timer
|
||||||
this.timerId = window.setTimeout(() => {
|
this.timerId = window.setTimeout(() => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user