Skip to content

Commit

Permalink
refactor: updated/commented leftover Date.now calls
Browse files Browse the repository at this point in the history
  • Loading branch information
porcellus committed Jan 17, 2024
1 parent c0627b4 commit fe671df
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bundle/bundle.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lib/build/fetch.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions lib/build/recipeImplementation.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions lib/ts/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,7 @@ export function setToken(tokenType: TokenType, value: string) {
if (value !== "") {
logDebugMessage(`setToken: saved ${tokenType} token into cookies`);
// We save the tokens with a 100-year expiration time
// We have to use the client side system clock here, because the cookie expiration will be counted based on that
return storeInCookies(name, value, Date.now() + 3153600000);
} else {
logDebugMessage(`setToken: cleared ${tokenType} token from cookies`);
Expand Down Expand Up @@ -786,6 +787,7 @@ async function saveTokensFromHeaders(response: Response) {
export async function saveLastAccessTokenUpdate() {
logDebugMessage("saveLastAccessTokenUpdate: called");

// We are saving the client side time here, but the actual value doesn't matter.
const now = Date.now().toString();
logDebugMessage("saveLastAccessTokenUpdate: setting " + now);
await storeInCookies(LAST_ACCESS_TOKEN_UPDATE, now, Number.MAX_SAFE_INTEGER);
Expand Down
5 changes: 3 additions & 2 deletions lib/ts/recipeImplementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { logDebugMessage } from "./logger";
import { STGeneralError } from "./error";
import { addInterceptorsToXMLHttpRequest } from "./xmlhttprequest";
import { normaliseSessionScopeOrThrowError, normaliseURLDomainOrThrowError } from "./utils";
import DateProviderReference from "./utils/dateProvider";

export default function RecipeImplementation(recipeImplInput: {
preAPIHook: RecipePreAPIHookFunction;
Expand Down Expand Up @@ -99,7 +100,7 @@ export default function RecipeImplementation(recipeImplInput: {
throw new Error("No session exists");
}

if (tokenInfo.ate < Date.now()) {
if (tokenInfo.ate < DateProviderReference.getReferenceOrThrow().dateProvider.now()) {
logDebugMessage("getAccessTokenPayloadSecurely: access token expired. Refreshing session");
let retry = await AuthHttpRequest.attemptRefreshingSession();
if (retry) {
Expand All @@ -124,7 +125,7 @@ export default function RecipeImplementation(recipeImplInput: {
return false;
}

if (tokenInfo.ate < Date.now()) {
if (tokenInfo.ate < DateProviderReference.getReferenceOrThrow().dateProvider.now()) {
logDebugMessage("doesSessionExist: access token expired. Refreshing session");

const preRequestLSS = await getLocalSessionState(false);
Expand Down

0 comments on commit fe671df

Please sign in to comment.