Skip to content

Commit ce169cb

Browse files
committed
fix(client): use crypto.randomUUID() only in secure contexts so recipe generation works on
the HTTP-served deployment instead of throwing and showing 'Something went wrong'
1 parent afb433f commit ce169cb

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

client/src/components/RecipeCard.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ type Status = 'idle' | 'loading' | 'success' | 'error'
99
type DietaryRestriction = 'Vegan' | 'Vegetarian' | 'Gluten Free' | 'Lactose Free'
1010
type LlmProvider = 'logos' | 'openai'
1111

12+
// crypto.randomUUID() is only available in secure contexts (HTTPS/localhost); the
13+
// deployed app is served over plain HTTP, so fall back to a non-crypto id there.
14+
function generateId(): string {
15+
if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
16+
return crypto.randomUUID()
17+
}
18+
return `${Date.now()}-${Math.random().toString(16).slice(2)}`
19+
}
20+
1221
const DIETARY_OPTIONS: DietaryRestriction[] = ['Vegan', 'Vegetarian', 'Gluten Free', 'Lactose Free']
1322

1423
const CHIPS = [
@@ -83,7 +92,7 @@ export function RecipeCard({ token, onListGenerated }: RecipeCardProps) {
8392
setIngredients(data.ingredients)
8493
setStatus('success')
8594
const saved = await onListGenerated?.({
86-
id: crypto.randomUUID(),
95+
id: generateId(),
8796
dish: data.dish,
8897
createdAt: new Date().toISOString(),
8998
ingredients: data.ingredients,

0 commit comments

Comments
 (0)