Edge Functions let you run code close to users for faster responses. Calling them from the client means your app can get data or do tasks quickly and securely.
You want to fetch data from your backend without exposing your database directly.
You need to run custom logic like sending emails or processing payments triggered by user actions.
You want to keep your app fast by running code near the user's location.
You want to keep sensitive operations on the server but trigger them from the app.
You want to handle user requests that require authentication and authorization.
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);