@@ -151,7 +151,7 @@ export const isDevelopmentMode = (): boolean => {
151151 * Contains constraints and shape definitions used across different form strategies
152152 */
153153const createBaseAuthForm = ( ) => ( {
154- id : 'error-fallback-form-' + crypto . randomUUID ( ) , // Generate unique form ID for fallback
154+ id : getBaseAuthFormId ( ) ,
155155 data : { username : '' , password : '' } ,
156156 constraints : {
157157 username : { minlength : 3 , maxlength : 24 , required : true , pattern : '[\\w]*' } ,
@@ -167,3 +167,25 @@ const createBaseAuthForm = () => ({
167167 password : { type : 'string' } ,
168168 } ,
169169} ) ;
170+
171+ /**
172+ * Generates a unique identifier for authentication form elements.
173+ *
174+ * Uses Web Crypto API's randomUUID() when available, falling back to a
175+ * timestamp-based random string for environments where crypto is unavailable.
176+ *
177+ * @returns A unique string identifier prefixed with 'error-fallback-form-'
178+ *
179+ * @example
180+ * ```typescript
181+ * const formId = getBaseAuthFormId();
182+ * // Returns: "error-fallback-form-550e8400-e29b-41d4-a716-446655440000"
183+ * // or: "error-fallback-form-1703875200000-abc123def"
184+ * ```
185+ */
186+ const getBaseAuthFormId = ( ) => {
187+ return (
188+ 'error-fallback-form-' +
189+ ( globalThis . crypto ?. randomUUID ?.( ) ?? `${ Date . now ( ) } -${ Math . random ( ) . toString ( 36 ) . slice ( 2 ) } ` )
190+ ) ; // Fallback when Web Crypto is unavailable
191+ } ;
0 commit comments