diff --git a/native_gg/src/authentication/AuthService.ts b/native_gg/src/authentication/AuthService.ts index dc99494a1..ad2a3ddb2 100644 --- a/native_gg/src/authentication/AuthService.ts +++ b/native_gg/src/authentication/AuthService.ts @@ -5,7 +5,7 @@ import * as WebBrowser from "expo-web-browser"; import * as v from "valibot"; import { clientID, redirectURL } from "../constants/env.ts"; import { Store } from "../constants/storage.ts"; -import { RefreshToken, refreshTokenSchema, getAccessToken, getRefreshToken, hasAccessExpired } from "./Utilities.ts"; +import { RefreshToken, refreshTokenSchema, getAccessToken, getRefreshToken, isValidAccess } from "./Utilities.ts"; import { BungieUser, BungieUserSchema, @@ -94,8 +94,8 @@ class AuthService { return new Promise((resolve, reject) => { if (AuthService.instance.authToken) { /// is the access token valid? - const hasExpired = hasAccessExpired(AuthService.instance.authToken); - if (hasExpired) { + const isValid = isValidAccess(AuthService.instance.authToken); + if (!isValid) { console.log("Token expired"); getAccessToken(AuthService.instance.authToken) .then((authToken) => { diff --git a/native_gg/src/authentication/Utilities.ts b/native_gg/src/authentication/Utilities.ts index 5ace34c54..09b9c46f8 100644 --- a/native_gg/src/authentication/Utilities.ts +++ b/native_gg/src/authentication/Utilities.ts @@ -86,7 +86,7 @@ export function getAccessToken(token: RefreshToken): Promise { }); } -export function hasAccessExpired(token: RefreshToken): boolean { +export function isValidAccess(token: RefreshToken): boolean { // Access lasts 3600 seconds (1 hour) if (token.time_stamp) { const lifeTime = token.expires_in; @@ -94,13 +94,13 @@ export function hasAccessExpired(token: RefreshToken): boolean { const timeThen = new Date(token.time_stamp); const secondsLeft = lifeTime - (timeNow.getTime() - timeThen.getTime()) / 1000; // Count anything less than 5 mins (345 seconds) as expired - return secondsLeft < 345; + return secondsLeft > 345; } return true; } -export function hasRefreshExpired(token: RefreshToken): boolean { +export function isValidRefresh(token: RefreshToken): boolean { // Refresh lasts 7,776,000 seconds (90 days) if (token.time_stamp) { const lifeTime = token.refresh_expires_in; @@ -108,7 +108,7 @@ export function hasRefreshExpired(token: RefreshToken): boolean { const timeThen = new Date(token.time_stamp); const secondsLeft = lifeTime - (timeNow.getTime() - timeThen.getTime()) / 1000; // Count anything less than 5 mins (345 seconds) as expired - return secondsLeft < 345; + return secondsLeft > 345; } return true;