Querying Data
Data access patterns for Handlet server components, actions, and services.
Handlet data access should keep tenant boundaries obvious and reusable.
Server components
Use the Supabase server client for read paths that render authenticated pages. RLS applies automatically for the signed-in user.
Server actions
Use enhanceAction for mutations. Validate input with schemas, then call a service or Supabase client from the server action boundary.
Services
Keep business decisions in pure services where possible. Inject dependencies so the same logic can be used from server actions, route handlers, tests, or workflow callbacks.
Admin client
Use the admin client only when a job must bypass RLS, such as controlled webhook, admin, or maintenance paths. Validate the target account_id and caller context before reading or writing.
Type safety
Regenerate database types after schema changes and use the generated table types instead of hand-written database shapes.