Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 469
fix(clerk-js): Cache logic around org ID pass to getToken()#4013
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
d7a2dc444a66d41bf4d40195172f9fa7815f5ac1e2e58e153c7eab6cFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| --- | ||
| --- | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -118,7 +118,9 @@ export class Session extends BaseResource implements SessionResource { | ||
| // e.g. session id is 'sess_abc12345' and jwt template name is 'haris' | ||
| // The session token ID will be 'sess_abc12345' and the jwt template token ID will be 'sess_abc12345-haris' | ||
| #getCacheId(template?: string, organizationId?: string) { | ||
| return [this.id, template, organizationId, this.updatedAt.getTime()].filter(Boolean).join('-'); | ||
| const resolvedOrganizationId = | ||
| typeof organizationId === 'undefined' ? this.lastActiveOrganizationId : organizationId; | ||
| return [this.id, template, resolvedOrganizationId, this.updatedAt.getTime()].filter(Boolean).join('-'); | ||
Comment on lines
+121
to
+123
MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. additional bug: when the token cache is hydrated on init, the cache key didn't include the organization ID. | ||
| } | ||
| protected fromJSON(data: SessionJSON | null): this { | ||
| @@ -151,12 +153,12 @@ export class Session extends BaseResource implements SessionResource { | ||
| return null; | ||
| } | ||
| const { | ||
| leewayInSeconds, | ||
| template, | ||
| skipCache = false, | ||
| organizationId = Session.clerk.organization?.id, | ||
| } = options || {}; | ||
| const { leewayInSeconds, template, skipCache = false } = options || {}; | ||
| // If no organization ID is provided, default to the selected organization in memory | ||
| // Note: this explicitly allows passing `null` or `""`, which should select the personal workspace. | ||
| const organizationId = | ||
| typeof options?.organizationId === 'undefined' ? Session.clerk.organization?.id : options?.organizationId; | ||
| if (!template && Number(leewayInSeconds) >= 60) { | ||
| throw new Error('Leeway can not exceed the token lifespan (60 seconds)'); | ||
| @@ -166,7 +168,7 @@ export class Session extends BaseResource implements SessionResource { | ||
| const cachedEntry = skipCache ? undefined : SessionTokenCache.get({ tokenId }, leewayInSeconds); | ||
| // Dispatch tokenUpdate only for __session tokens with the session's active organization ID, and not JWT templates | ||
| const shouldDispatchTokenUpdate = !template && options?.organizationId === Session.clerk.organization?.id; | ||
MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One bug: | ||
| const shouldDispatchTokenUpdate = !template && organizationId === Session.clerk.organization?.id; | ||
| if (cachedEntry) { | ||
| const cachedToken = await cachedEntry.tokenResolver; | ||
| @@ -178,7 +180,7 @@ export class Session extends BaseResource implements SessionResource { | ||
| } | ||
| const path = template ? `${this.path()}/tokens/${template}` : `${this.path()}/tokens`; | ||
| // TODO: update template endpoint to accept organizationId | ||
| const params = template ? {} : { ...(organizationId && { organizationId }) }; | ||
| const params = template ? {} : { organizationId }; | ||
| const tokenResolver = Token.create(path, params); | ||
| SessionTokenCache.set({ tokenId, tokenResolver }); | ||
| return tokenResolver.then(token => { | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes a bug in an unreleased PR, so it didn't feel necessary to have an entry for this. (#3786)