mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-13 03:32:13 +00:00
fix: refresh session token
This commit is contained in:
parent
93c6ef8510
commit
e56a8209e1
1 changed files with 8 additions and 2 deletions
|
@ -8,6 +8,8 @@ export class HydraApi {
|
||||||
|
|
||||||
private static readonly EXPIRATION_OFFSET_IN_MS = 1000 * 60 * 5;
|
private static readonly EXPIRATION_OFFSET_IN_MS = 1000 * 60 * 5;
|
||||||
|
|
||||||
|
private static secondsToMilliseconds = (seconds: number) => seconds * 1000;
|
||||||
|
|
||||||
private static userAuth = {
|
private static userAuth = {
|
||||||
authToken: "",
|
authToken: "",
|
||||||
refreshToken: "",
|
refreshToken: "",
|
||||||
|
@ -29,7 +31,9 @@ export class HydraApi {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
|
|
||||||
const tokenExpirationTimestamp =
|
const tokenExpirationTimestamp =
|
||||||
now.getTime() + expiresIn - this.EXPIRATION_OFFSET_IN_MS;
|
now.getTime() +
|
||||||
|
this.secondsToMilliseconds(expiresIn) -
|
||||||
|
this.EXPIRATION_OFFSET_IN_MS;
|
||||||
|
|
||||||
this.userAuth = {
|
this.userAuth = {
|
||||||
authToken: accessToken,
|
authToken: accessToken,
|
||||||
|
@ -110,7 +114,9 @@ export class HydraApi {
|
||||||
const { accessToken, expiresIn } = response.data;
|
const { accessToken, expiresIn } = response.data;
|
||||||
|
|
||||||
const tokenExpirationTimestamp =
|
const tokenExpirationTimestamp =
|
||||||
now.getTime() + expiresIn - this.EXPIRATION_OFFSET_IN_MS;
|
now.getTime() +
|
||||||
|
this.secondsToMilliseconds(expiresIn) -
|
||||||
|
this.EXPIRATION_OFFSET_IN_MS;
|
||||||
|
|
||||||
this.userAuth.authToken = accessToken;
|
this.userAuth.authToken = accessToken;
|
||||||
this.userAuth.expirationTimestamp = tokenExpirationTimestamp;
|
this.userAuth.expirationTimestamp = tokenExpirationTimestamp;
|
||||||
|
|
Loading…
Reference in a new issue