@tuturuuu/supabase
The@tuturuuu/supabase
package provides type-safe Supabase client utilities for the Tuturuuu platform with different privilege levels and execution contexts.
Installation
Client Types
createClient()
- User-Scoped Client
Use Case: Standard operations respecting Row-Level Security (RLS) policies.
Context: Server Components, Server Actions, API Routes
Privilege Level: Current authenticated user
- ✅ Respects RLS policies
- ✅ Safe for user-initiated operations
- ❌ Cannot bypass workspace isolation
- ❌ Cannot perform privileged operations
createAdminClient()
- Service Role Client
Use Case: Privileged operations bypassing RLS (admin tasks, system operations).
Context: Server-side only (never expose to client)
Privilege Level: Service role (bypasses RLS)
- ✅ Only use server-side
- ✅ Only for privileged operations
- ❌ NEVER expose to client
- ❌ NEVER use for user-initiated queries (always prefer
createClient()
)
createDynamicClient()
- Middleware Client
Use Case: Middleware and edge runtime contexts.
Context: Next.js middleware, edge functions
Common Patterns
Authentication
Get Current User
Server Action with Auth Check
Workspace Operations
Get User’s Workspaces
Check Workspace Permission
Data Fetching
Paginated Query
Filtered Query with Relations
Realtime Subscriptions
Type Safety
Using Generated Types
Custom Type Helpers
Error Handling
Standard Pattern
With Try-Catch
Storage Operations
Upload File
Download File
Best Practices
✅ DO
-
Use
createClient()
by default -
Check authentication early
-
Handle errors explicitly
-
Use TypeScript types
-
Limit data fetching
❌ DON’T
-
Never use
createAdminClient()
for user operations -
Don’t expose service role key
-
Don’t ignore errors
-
Don’t fetch unnecessary data