Skip to content

Commit

Permalink
Refresh access token if it's old enough
Browse files Browse the repository at this point in the history
  • Loading branch information
DoctorMcKay committed Oct 27, 2023
1 parent 145e401 commit 2a775c3
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/LoginSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ export default class LoginSession extends TypedEmitter<LoginSessionEvents> {
private _pollTimer?: Timeout;
private _pollingCanceled?: boolean;

private _accessTokenSetAt?: Date;

/**
* @param {EAuthTokenPlatformType} platformType - A value from {@link EAuthTokenPlatformType}.
* You should set this to the appropriate platform type for your desired usage.
Expand Down Expand Up @@ -260,6 +262,7 @@ export default class LoginSession extends TypedEmitter<LoginSessionEvents> {

// Everything checks out
this._accessToken = token;
this._accessTokenSetAt = new Date();
}

/**
Expand Down Expand Up @@ -801,7 +804,8 @@ export default class LoginSession extends TypedEmitter<LoginSessionEvents> {
// The same is likely true for WebBrowser, but we want to mimic official behavior as closely as possible to avoid
// any potential future breakage.
if ([EAuthTokenPlatformType.SteamClient, EAuthTokenPlatformType.MobileApp].includes(this._platformType)) {
if (!this.accessToken) {
if (!this.accessToken || Date.now() - this._accessTokenSetAt.getTime() > (1000 * 60 * 10)) {
// Refresh our access token if we either don't have one, or the token we have is greater than 10 minutes old
await this.refreshAccessToken();
}

Expand Down

0 comments on commit 2a775c3

Please sign in to comment.