|
1 | 1 | import type { TokenResource } from '@clerk/types';
|
2 | 2 |
|
3 | 3 | import { debugLogger } from '@/utils/debug';
|
| 4 | +import { buildTokenId } from '@/utils/tokenId'; |
4 | 5 |
|
5 | 6 | import { Token } from './resources/internal';
|
6 | 7 |
|
@@ -141,14 +142,6 @@ export class TokenCacheKey {
|
141 | 142 | }
|
142 | 143 | }
|
143 | 144 |
|
144 |
| -/** |
145 |
| - * Generates a unique token identifier from session context. |
146 |
| - * Format: `sessionId-template-organizationId` (omitting falsy values). |
147 |
| - */ |
148 |
| -const computeTokenId = (sessionId: string, template?: string, organizationId?: string | null): string => { |
149 |
| - return [sessionId, template, organizationId].filter(Boolean).join('-'); |
150 |
| -}; |
151 |
| - |
152 | 145 | /**
|
153 | 146 | * Message format for BroadcastChannel token synchronization between tabs.
|
154 | 147 | */
|
@@ -231,7 +224,7 @@ const MemoryTokenCache = (prefix = KEY_PREFIX): TokenCache => {
|
231 | 224 | * Validates token ID, parses JWT, and updates cache if token is newer than existing entry.
|
232 | 225 | */
|
233 | 226 | const handleBroadcastMessage = async ({ data }: MessageEvent<SessionTokenEvent>) => {
|
234 |
| - const expectedTokenId = computeTokenId(data.sessionId, data.template, data.organizationId); |
| 227 | + const expectedTokenId = buildTokenId(data.sessionId, data.template, data.organizationId); |
235 | 228 | if (data.tokenId !== expectedTokenId) {
|
236 | 229 | debugLogger.warn(
|
237 | 230 | 'Ignoring token broadcast with mismatched tokenId',
|
@@ -318,7 +311,7 @@ const MemoryTokenCache = (prefix = KEY_PREFIX): TokenCache => {
|
318 | 311 | setInternal(entry);
|
319 | 312 |
|
320 | 313 | if (broadcast && channel) {
|
321 |
| - const expectedTokenId = computeTokenId(broadcast.sessionId, broadcast.template, broadcast.organizationId); |
| 314 | + const expectedTokenId = buildTokenId(broadcast.sessionId, broadcast.template, broadcast.organizationId); |
322 | 315 | if (entry.tokenId !== expectedTokenId) {
|
323 | 316 | return;
|
324 | 317 | }
|
|
0 commit comments