Skip to content

Commit

Permalink
hasAccessExpired -> isValidAccess
Browse files Browse the repository at this point in the history
  • Loading branch information
NigelBreslaw committed Feb 17, 2024
1 parent d051ffb commit 3973713
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions native_gg/src/authentication/AuthService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) => {
Expand Down
8 changes: 4 additions & 4 deletions native_gg/src/authentication/Utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,29 +86,29 @@ export function getAccessToken(token: RefreshToken): Promise<RefreshToken> {
});
}

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;
const timeNow = new Date();
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;
const timeNow = new Date();
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;
Expand Down

0 comments on commit 3973713

Please sign in to comment.