mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-21 16:14:45 +00:00
fix(app): guard randomUUID in insecure browser contexts (#13237)
Co-authored-by: Selim <31136147+selimerunkut@users.noreply.github.com>
This commit is contained in:
12
packages/app/src/utils/uuid.ts
Normal file
12
packages/app/src/utils/uuid.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
const fallback = () => Math.random().toString(16).slice(2)
|
||||
|
||||
export function uuid() {
|
||||
const c = globalThis.crypto
|
||||
if (!c || typeof c.randomUUID !== "function") return fallback()
|
||||
if (typeof globalThis.isSecureContext === "boolean" && !globalThis.isSecureContext) return fallback()
|
||||
try {
|
||||
return c.randomUUID()
|
||||
} catch {
|
||||
return fallback()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user