diff --git a/npm/ng-packs/packages/oauth/src/lib/services/memory-token-storage.service.ts b/npm/ng-packs/packages/oauth/src/lib/services/memory-token-storage.service.ts index 390cdccea5..d8708e02f5 100644 --- a/npm/ng-packs/packages/oauth/src/lib/services/memory-token-storage.service.ts +++ b/npm/ng-packs/packages/oauth/src/lib/services/memory-token-storage.service.ts @@ -31,7 +31,7 @@ export class MemoryTokenStorageService implements OAuthStorage { // @ts-ignore this.worker = new SharedWorker( new URL('../workers/token-storage.worker.ts', import.meta.url), - { type: 'module', name: 'oauth-token-storage' } + { name: 'oauth-token-storage' } ); this.port = this.worker.port; @@ -72,11 +72,6 @@ export class MemoryTokenStorageService implements OAuthStorage { if (!this.keysShouldStoreInMemory.includes(key)) { return this.localStorageService.getItem(key); } - -/* if (this.useSharedWorker) { - return this.cache.get(key) || null; - }*/ - return this.cache.get(key) || null; } @@ -87,7 +82,7 @@ export class MemoryTokenStorageService implements OAuthStorage { } if (this.useSharedWorker && this.port) { - // this.cache.set(key, value); + this.cache.set(key, value); this.port.postMessage({ action: 'set', key, value }); } else { this.cache.set(key, value); @@ -115,9 +110,8 @@ export class MemoryTokenStorageService implements OAuthStorage { this.cache.clear(); } - private checkAuthStateChanges(key: string): void { - console.log("current access token:", this.cache.get('access_token')); - if (key !== 'access_token' && !this.cache.get('access_token')) { + private checkAuthStateChanges = (key: string) => { + if (key === 'access_token' && !this.cache.get('access_token')) { this.refreshDocument(); } } diff --git a/npm/ng-packs/packages/oauth/src/lib/workers/token-storage.worker.ts b/npm/ng-packs/packages/oauth/src/lib/workers/token-storage.worker.ts index 19b3537875..a223f948be 100644 --- a/npm/ng-packs/packages/oauth/src/lib/workers/token-storage.worker.ts +++ b/npm/ng-packs/packages/oauth/src/lib/workers/token-storage.worker.ts @@ -23,18 +23,30 @@ self.onconnect = (event: MessageEvent) => { case 'set': if (key && value !== undefined) { tokenStore.set(key, value); - ports.forEach(p => p.postMessage({ action: 'set', key, value })); + ports.forEach(p => { + if (p !== port) { + p.postMessage({ action: 'set', key, value }); + } + }); } break; case 'remove': if (key) { tokenStore.delete(key); - ports.forEach(p => p.postMessage({ action: 'remove', key })); + ports.forEach(p => { + if (p !== port) { + p.postMessage({ action: 'remove', key }); + } + }); } break; case 'clear': tokenStore.clear(); - ports.forEach(p => p.postMessage({ action: 'clear' })); + ports.forEach(p => { + if (p !== port) { + p.postMessage({ action: 'clear' }); + } + }); break; case 'get': if (key) { @@ -46,10 +58,6 @@ self.onconnect = (event: MessageEvent) => { }; port.start(); - - tokenStore.forEach((value, key) => { - port.postMessage({ action: 'set', key, value }); - }); }; export {};