Skip to content

Commit 3028ffc

Browse files
Use Effect UUID generator as randomUUID fallback
- Replace manual UUID byte formatting fallback in `apps/web/src/lib/utils.ts` - Use `Effect.runSync(Random.nextUUIDv4)` when `crypto.randomUUID` is unavailable
1 parent d21fbf9 commit 3028ffc

1 file changed

Lines changed: 3 additions & 7 deletions

File tree

apps/web/src/lib/utils.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { CommandId, MessageId, ProjectId, ThreadId } from "@t3tools/contracts";
22
import { type CxOptions, cx } from "class-variance-authority";
33
import { twMerge } from "tailwind-merge";
4+
import * as Random from "effect/Random";
5+
import * as Effect from "effect/Effect";
46

57
export function cn(...inputs: CxOptions) {
68
return twMerge(cx(inputs));
@@ -18,13 +20,7 @@ export function randomUUID(): string {
1820
if (typeof crypto.randomUUID === "function") {
1921
return crypto.randomUUID();
2022
}
21-
// Fallback for non-secure contexts (plain HTTP on non-localhost)
22-
const bytes = new Uint8Array(16);
23-
crypto.getRandomValues(bytes);
24-
bytes[6] = (bytes[6] & 0x0f) | 0x40;
25-
bytes[8] = (bytes[8] & 0x3f) | 0x80;
26-
const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
27-
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
23+
return Effect.runSync(Random.nextUUIDv4);
2824
}
2925

3026
export const newCommandId = (): CommandId => CommandId.makeUnsafe(randomUUID());

0 commit comments

Comments
 (0)