B. Missing await keyword for the async invoke call
C. Using console.log instead of alert
D. Incorrect function name 'dataFetch'
Solution
Step 1: Check async call usage
supabase.functions.invoke() returns a promise and must be awaited.
Step 2: Identify missing await
The code assigns the promise to response without awaiting, so response.data is undefined.
Final Answer:
Missing await keyword for the async invoke call -> Option B
Quick Check:
Async calls need await [OK]
Hint: Always await async invoke calls [OK]
Common Mistakes:
Forgetting await on async functions
Assuming invoke returns data synchronously
Ignoring promise nature of invoke()
5. You want to send JSON data {"userId": 123} to an Edge Function named getUserData and handle errors properly. Which code snippet correctly does this?
hard
A. const { data, error } = await supabase.functions.invoke('getUserData', body: { userId: 123 }); if (error) console.error(error); else console.log(data);
B. const { data, error } = supabase.functions.invoke('getUserData', { body: JSON.stringify({ userId: 123 }) }); if (error) console.error(error); else console.log(data);