Acesso pelo IP da rede (http://192.168...) nao e contexto seguro e o navegador nao expoe crypto.randomUUID, derrubando a conclusao do pedido. Helper randomUUID() cai para UUID v4 via crypto.getRandomValues. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
13 lines
718 B
TypeScript
13 lines
718 B
TypeScript
// crypto.randomUUID só existe em contexto seguro (HTTPS/localhost). Acessando o
|
|
// dev server pelo IP da rede (http://192.168...) ela é undefined — fallback gera
|
|
// UUID v4 com crypto.getRandomValues, disponível em qualquer contexto.
|
|
export function randomUUID(): string {
|
|
if (typeof crypto.randomUUID === 'function') return crypto.randomUUID();
|
|
|
|
const bytes = crypto.getRandomValues(new Uint8Array(16));
|
|
bytes[6] = (bytes[6] & 0x0f) | 0x40; // versão 4
|
|
bytes[8] = (bytes[8] & 0x3f) | 0x80; // variante RFC 4122
|
|
const hex = [...bytes].map((b) => b.toString(16).padStart(2, '0')).join('');
|
|
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
}
|