Skip to content

Commit ab5f020

Browse files
committed
only attempt initial refresh when likely to succeed
We now set a javascript-accessible `workos-has-session` cookie when the user is logged in. We don't need to attempt to refresh if that cookie is not present.
1 parent 27ba2c0 commit ab5f020

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/create-client.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ describe("create-client", () => {
1919
sessionStorage.removeItem(storageKeys.codeVerifier);
2020
sessionStorage.removeItem(ORGANIZATION_ID_SESSION_STORAGE_KEY);
2121
localStorage.removeItem(storageKeys.refreshToken);
22+
23+
// assume we have a session already for all these tests
24+
jest
25+
.spyOn(document, "cookie", "get")
26+
.mockReturnValue(`workos-has-session=1`);
2227
});
2328

2429
afterEach(() => {

src/create-client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export class Client {
107107
const searchParams = new URLSearchParams(window.location.search);
108108
if (isRedirectCallback(this.#redirectUri, searchParams)) {
109109
await this.#handleCallback();
110-
} else {
110+
} else if (document.cookie.includes("workos-has-session=")) {
111111
try {
112112
await this.#refreshSession();
113113
this.#scheduleAutomaticRefresh();

0 commit comments

Comments
 (0)