Skip to content

Commit

Permalink
Add token refresh when sessionRoom missing
Browse files Browse the repository at this point in the history
  • Loading branch information
backspace committed Jan 20, 2025
1 parent a246bac commit 86efa43
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions packages/host/app/services/realm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,15 +332,20 @@ class RealmResource {
return;
}

// token expiration is unix time (seconds)
let expirationMs = this.claims.exp * 1000;
if (!this.claims.sessionRoom) {
console.log('JWT has no session room, renewing');
} else {
// token expiration is unix time (seconds)
let expirationMs = this.claims.exp * 1000;

let refreshMs = Math.max(
expirationMs - Date.now() - tokenRefreshPeriodSec * 1000,
0,
);
let 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 86efa43

Please sign in to comment.