Skip to content

Conversation

@erdemcaygor
Copy link
Contributor

@erdemcaygor erdemcaygor commented Oct 24, 2025

Description

Resolves #23930

Improvements

  • Store sensitive tokens in memory
  • Use Web Workers for state sharing between tabs

@erdemcaygor erdemcaygor marked this pull request as ready for review October 27, 2025 13:58
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances authentication token handling in Angular by implementing a SharedWorker-based token storage system. The changes improve cross-tab token synchronization and move sensitive tokens from localStorage to in-memory storage for better security.

  • Introduces a SharedWorker for cross-tab token synchronization
  • Implements MemoryTokenStorageService to store sensitive tokens in memory instead of localStorage
  • Adds error handling for token refresh operations

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
token-storage.worker.ts New SharedWorker implementation for cross-tab token storage synchronization
memory-token-storage.service.ts New service that stores sensitive OAuth tokens in memory with SharedWorker support
storage.factory.ts Updated to use MemoryTokenStorageService instead of AbpLocalStorageService
oauth.service.ts Added try-catch error handling around token refresh operation
index.ts Added export for the new MemoryTokenStorageService

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

try {
return this.oAuthService.refreshToken();
} catch (error) {
return Promise.resolve();
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The catch block silently swallows errors without logging or providing any feedback. Consider logging the error or returning a rejected promise with an appropriate error message to help with debugging authentication issues.

Suggested change
return Promise.resolve();
console.error('Error during token refresh:', error);
return Promise.reject(error);

Copilot uses AI. Check for mistakes.
}

if (this.useSharedWorker && this.port) {
// this.cache.delete(key);
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented-out code. If this line is needed, it should be uncommented and executed; otherwise, it should be deleted entirely.

Suggested change
// this.cache.delete(key);

Copilot uses AI. Check for mistakes.
Comment on lines +28 to +32
// @ts-ignore
if (typeof SharedWorker !== 'undefined') {
try {
// @ts-ignore
this.worker = new SharedWorker(
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace @ts-ignore comments with proper TypeScript type declarations or type guards. The repeated use of @ts-ignore suppresses type checking and can hide potential runtime errors.

Copilot uses AI. Check for mistakes.
}
};

console.log('✅ Using SharedWorker for cross-tab token storage');
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove or replace console.log statements in production code. Consider using a proper logging service or removing this debug statement entirely.

Suggested change
console.log('✅ Using SharedWorker for cross-tab token storage');

Copilot uses AI. Check for mistakes.

console.log('✅ Using SharedWorker for cross-tab token storage');
} catch (error) {
console.warn('⚠️ SharedWorker failed:', error);
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a proper logging service instead of console.warn for error reporting in production code. This would allow better error tracking and debugging capabilities.

Copilot uses AI. Check for mistakes.
this.useSharedWorker = false;
}
} else {
console.warn('⚠️ SharedWorker not supported');
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a proper logging service instead of console.warn. This would provide consistent logging throughout the application.

Copilot uses AI. Check for mistakes.
@erdemcaygor erdemcaygor added this to the 10.1-preview milestone Oct 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Angular - Improve Authentication Token Handling

2 participants