diff --git a/docs/development/CENTRAL.md b/docs/development/CENTRAL.md index 8ebab89..a76e4e6 100644 --- a/docs/development/CENTRAL.md +++ b/docs/development/CENTRAL.md @@ -10,6 +10,7 @@ The project has successfully migrated from a .NET backend to a Node.js Modular M - **[2025-12-14] Cleanup**: Removed Tournament Mode and simplified pack display as requested. [Link](./devlog/2025-12-14-211500_remove_tournament_mode.md) - **[2025-12-14] UI Tweak**: Auto-configured generation mode based on source selection. [Link](./devlog/2025-12-14-212000_ui_simplification.md) - **[2025-12-14] Multiplayer Game Plan**: Plan for Real Game & Online Multiplayer. [Link](./devlog/2025-12-14-212500_multiplayer_game_plan.md) +- **[2025-12-14] Bug Fix**: Fixed `crypto.randomUUID` error for non-secure contexts. [Link](./devlog/2025-12-14-214400_fix_uuid_error.md) ## Active Modules 1. **Cube Manager**: Fully functional (Parsing, Fetching, Pack Generation). diff --git a/docs/development/devlog/2025-12-14-214400_fix_uuid_error.md b/docs/development/devlog/2025-12-14-214400_fix_uuid_error.md new file mode 100644 index 0000000..4e817dc --- /dev/null +++ b/docs/development/devlog/2025-12-14-214400_fix_uuid_error.md @@ -0,0 +1,15 @@ +# Fix UUID Error in Insecure Contexts + +## Problem +The user reported a `TypeError: crypto.randomUUID is not a function` when accessing the application from a public IP. This is because `crypto.randomUUID()` is part of the Web Crypto API, which is often restricted to secure contexts (HTTPS) or localhost. When accessing via `http://PUBLIC_IP:PORT`, the browser disables this API. + +## Solution +We need to implement a fallback UUID generation method that works in non-secure contexts. + +## Plan +1. Modify `src/client/src/services/PackGeneratorService.ts`. +2. Add a private method `generateUUID()` to the `PackGeneratorService` class (or a standalone helper function in the module) that: + * Checks if `crypto.randomUUID` is available. + * If yes, uses it. + * If no, uses a fallback algorithm (e.g., `Math.random()` based v4 UUID generation). +3. Replace the call `crypto.randomUUID()` with this new method. diff --git a/src/client/src/services/PackGeneratorService.ts b/src/client/src/services/PackGeneratorService.ts index 0ca8f1e..8177991 100644 --- a/src/client/src/services/PackGeneratorService.ts +++ b/src/client/src/services/PackGeneratorService.ts @@ -63,7 +63,7 @@ export class PackGeneratorService { } const cardObj: DraftCard = { - id: crypto.randomUUID(), + id: this.generateUUID(), scryfallId: cardData.id, name: cardData.name, rarity: rarity, @@ -298,4 +298,15 @@ export class PackGeneratorService { } return newArray; } + + private generateUUID(): string { + if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') { + return crypto.randomUUID(); + } + // Fallback for insecure contexts or older browsers + return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { + var r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8); + return v.toString(16); + }); + } }