Supabase Backend Skill
When interacting with Supabase:
Client Usage
- •Import the typed client from
src/integrations/supabase/client.ts.typescriptimport { supabase } from "@/integrations/supabase/client";
Type Safety
- •Always leverage the generated Database types.
- •Queries should automatically be typed if the client is typed correctly.
typescript
const { data, error } = await supabase .from('jobs') .select('*'); // data is typed as Job[]
Error Handling
- •Always check for
errorafter a request.typescriptif (error) { console.error('Error fetching jobs:', error); toast.error('Failed to load jobs'); return; }
Auth
- •Use
supabase.auth.getUser()to get the current user server-side or in protected routes. - •Use
useAuthhook (if available) or listen toonAuthStateChangefor client-side auth state.