fix(auth-js): replace Math.random with crypto based UUID to support N… #1839
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Next.js 16 App Router enforces deterministic rendering for Server Components.
The previous uuid() implementation in @supabase/auth-js relied on Math.random(),
which caused prerender errors even when no queries were executed.
This update replaces Math.random() with crypto.getRandomValues in browsers
and crypto.randomFillSync in Node, providing SSR-safe, fully synchronous UUID v4 generation.
Changes
Closes #40273
🔍 Description
Fixes SSR prerender errors in Next.js 16 caused by Math.random() in uuid().
What changed?
Replaced Math.random() with crypto.getRandomValues in browsers and crypto.randomFillSync in Node. Updated uuid() to remain fully synchronous and UUID v4 compliant.
Why was this change needed?
To ensure Server Components render deterministically and prevent Next.js 16 prerender errors.
📸 Screenshots/Examples
N/A — code change only.
🔄 Breaking changes
📋 Checklist
npx nx formatto ensure consistent code formatting📝 Additional notes
This is a low-level crypto fix; no functional changes to existing APIs.