Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(chrome-extension): Clear JWT on init, prior to polling #3686

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/blue-jokes-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@clerk/chrome-extension": patch
---

Clear JWT on initial load prior to polling to ensure the extension has the newest possible JWT
5 changes: 5 additions & 0 deletions packages/chrome-extension/src/singleton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ export async function buildClerk({

// Set up JWT handler and attempt to get JWT from storage on initialization
const jwt = JWTHandler(storageCache, { ...getClientCookieParams, frontendApi: key.frontendApi });

// Clear JWT on initial load
await jwt.clear();

// Poll for new JWT
void jwt.poll();

// Create Clerk instance
Expand Down
11 changes: 9 additions & 2 deletions packages/chrome-extension/src/utils/jwt-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,19 @@ export function JWTHandler(store: StorageCache, { frontendApi, ...cookieParams }
return syncedJWT?.value;
};

/**
* Removes the JWT value to the active store.
*/
const clear = async () => {
await store.remove(CACHE_KEY);
};

/**
* Polls for the synced session JWT via the get() function.
*
* @param delayInMs: Polling delay in milliseconds (default: 1500ms)
*/
const poll = async (delayInMs: number = 1500) => {
const poll = async (delayInMs = 1500) => {
const { run, stop } = Poller({ delayInMs });

void run(async () => {
Expand All @@ -62,5 +69,5 @@ export function JWTHandler(store: StorageCache, { frontendApi, ...cookieParams }
});
};

return { get, poll, set };
return { clear, get, poll, set };
}
Loading