Skip to content

Commit

Permalink
Add tick before trying to refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
backspace committed Jan 20, 2025
1 parent 41e70c9 commit e623c80
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/host/app/services/realm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,21 +332,23 @@ class RealmResource {
return;
}

let refreshMs = 0;

if (!this.claims.sessionRoom) {
// Force JWT renewal to ensure presence of sessionRoom property
console.log(`JWT for realm ${this.url} has no session room, renewing`);
} else {
// token expiration is unix time (seconds)
let expirationMs = this.claims.exp * 1000;

let refreshMs = Math.max(
refreshMs = Math.max(
expirationMs - Date.now() - tokenRefreshPeriodSec * 1000,
0,
);

await rawTimeout(refreshMs);
}

await rawTimeout(refreshMs);

if (!this.loggingIn) {
this.loggingIn = this.loginTask.perform();
await this.loggingIn;
Expand Down

0 comments on commit e623c80

Please sign in to comment.