diff --git a/frontend/src/redux/session/klage/helpers.ts b/frontend/src/redux/session/klage/helpers.ts index 5b3768c8..8f31741a 100644 --- a/frontend/src/redux/session/klage/helpers.ts +++ b/frontend/src/redux/session/klage/helpers.ts @@ -10,7 +10,7 @@ export const createSessionCase = ( innsendingsytelse: Innsendingsytelse, internalSaksnummer: string | null, ): ISessionCase => ({ - id: crypto.randomUUID(), + id: getId(), type, innsendingsytelse, foedselsnummer: '', @@ -27,3 +27,19 @@ export const createSessionCase = ( modifiedByUser: new Date().toISOString(), caseIsAtKA: null, }); + +const SUPPORTS_CRYPTO = + 'crypto' in window && + typeof window.crypto === 'object' && + window.crypto !== null && + 'getRandomValues' in window.crypto && + typeof window.crypto.getRandomValues === 'function'; + +const fallbackIdGenerator = (): `${string}-${string}` => { + const now = new Date().getTime(); + const random = Math.random().toString(36).substring(2); + + return `${now}-${random}`; +}; + +const getId = SUPPORTS_CRYPTO ? crypto.randomUUID : fallbackIdGenerator;