diff --git a/utils/helpers.ts b/utils/helpers.ts index 65b342d..47a9f99 100644 --- a/utils/helpers.ts +++ b/utils/helpers.ts @@ -162,13 +162,21 @@ export const deepClone = (obj: T): T => { // Generate Random ID (cryptographically secure) export const generateId = (): string => { + const timestamp = Date.now().toString(36); if (typeof window !== 'undefined' && window.crypto) { const array = new Uint32Array(2); window.crypto.getRandomValues(array); - return array[0].toString(36) + array[1].toString(36) + Date.now().toString(36); + return array[0].toString(36) + array[1].toString(36) + timestamp; } - // Fallback for SSR (non-sensitive context) - return Date.now().toString(36) + Math.random().toString(36).substring(2); + // SSR fallback using Node.js crypto + if (typeof globalThis !== 'undefined' && globalThis.crypto) { + const array = new Uint32Array(2); + globalThis.crypto.getRandomValues(array); + return array[0].toString(36) + array[1].toString(36) + timestamp; + } + // Last resort: timestamp-based only (no Math.random) + const counter = (Date.now() % 1000000).toString(36); + return timestamp + counter + process.hrtime?.()[1]?.toString(36) || timestamp + counter; }; // Debounce Function