Overview
Supabase-specific patterns for building secure, real-time applications. Covers RLS policies, edge functions, real-time, storage, and auth.
Capabilities
- Implement Row Level Security (RLS) for multi-tenant data
- Write Supabase Edge Functions for serverless logic
- Set up real-time subscriptions for live data
- Integrate Supabase Auth with social providers
- Use Supabase Storage for file uploads
When to Use
Trigger phrases:
"supabase patterns"
"Supabase patterns — Row Level Security, edge functions, real-time subscriptions,"
Building multi-tenant SaaS with Supabase
Need real-time features (live updates, presence)
Serverless backend with Edge Functions
File storage and CDN for user uploads
When NOT to Use
- Task is about deployment, not development (use deploy skills)
- Task is about code review, not writing (use review skills)
- You need to understand existing code first (use research skills)
- Task is about testing only (use test skills)
- Requirements are unclear (clarify first)
- Task is trivially simple (single line fix)
Pseudo Code
The supabase-patterns workflow follows a standard pipeline pattern.
Core flow:
# supabase-patterns primary flow
input = prepare(raw_data)
result = process(input, config={auth, edge, functions, integration, level})
validate(result)
deliver(result)
Error handling:
on error:
log(error_details)
retry_with_backoff(max=3)
if still_failing: alert_and_escalate()
Row Level Security
-- Users can only see their own data
CREATE POLICY "users_own_data" ON orders
FOR ALL USING (auth.uid() = user_id);
-- Team members can see team data
CREATE POLICY "team_access" ON projects
FOR SELECT USING (
team_id IN (SELECT team_id FROM team_members WHERE user_id = auth.uid())
);
Edge Function
// supabase/functions/hello/index.ts
Deno.serve(async (req) => {
const { name } = await req.json()
const supabase = createClient(
Deno.env.get('SUPABASE_URL')!,
Deno.env.get('SUPABASE_ANON_KEY')!
)
const { data } = await supabase.from('greetings').insert({ name })
return new Response(JSON.stringify(data))
})
Real-time Subscription
const channel = supabase
.channel('orders')
.on('postgres_changes', { event: '*', schema: 'public', table: 'orders' }, handleUpdate)
.subscribe()
Common Patterns
- RLS always on: Enable RLS on every table — no exceptions
- Edge Functions for webhooks: Process Stripe, email events serverlessly
- Real-time for collaboration: Use presence and broadcast for multi-user features
Setup and Configuration
Project Setup
- Create a Supabase project — Start a new project in the Supabase dashboard, then copy the project URL and anon key.
- Install the SDK —
npm install @supabase/supabase-js
- Configure auth — Enable email/password, OAuth providers (Google, GitHub), or magic links in the Supabase dashboard.
- Define schema — Create tables, enable Row Level Security, write RLS policies, set up triggers.
- Build queries — Use the Supabase client for select, insert, update, delete with chained filters.
- Add real-time — Subscribe to table changes with Supabase Realtime channels.
Client Initialization
import { createClient } from '@supabase/supabase-js';
const supabase = createClient(process.env.SUPABASE_URL, process.env.SUPABASE_ANON_KEY);
Auth Example
const { data: { user } } = await supabase.auth.signUp({
email: 'user@example.com',
password: 'password123',
});
Query with Joins
const { data: posts } = await supabase
.from('posts')
.select('*, author:profiles(*)')
.eq('status', 'published')
.order('created_at', { ascending: false });
How to Use
- Understand the requirement and existing codebase patterns
- Design the solution with error handling and testability in mind
- Implement incrementally with tests for each change
- Verify against expected outcomes (manual and automated)
- Document usage, edge cases, and integration points
- Review with team before merging to shared branches
Red Flags
- Skipping tests to ship faster: Untested code breaks in production when you least expect it
- No error handling in production code: Unhandled errors crash services and lose user data
- Hardcoded configuration values: Hardcoded values prevent environment switching and leak secrets
- Ignoring security implications: Missing input validation, auth bypasses, and injection vulnerabilities
- Over-engineering simple solutions: Premature abstraction adds complexity without proportional benefit
Verification
Process
- Analyze the task requirements
- Apply domain expertise
- Verify output quality
Anti-Rationalization Table
| Rationalization |
Reality |
| "Tests slow me down" |
Bugs slow you down 10x more. Tests are speed, not overhead. |
| "I will refactor later" |
Technical debt compounds. Refactor as you go. |
| "It works on my machine" |
If it is not in CI, it does not work. Ship proof, not claims. |
| "RLS is optional" |
Without RLS, any authenticated user can access any data. |
| "I will add auth later" |
Retrofitting auth is 10x harder than building with it from day one. |
1---2name: supabase-patterns3description: Use when supabase patterns — Row Level Security, edge functions, real-time4 subscriptions, auth integration, setup, and configuration. Use when working with5 supabase patterns.6domain: development7author: oyi778license: Apache-2.09subdomain: software-development10tags:11- coding12- patterns13- software-engineering14- supabase15- testing16- database17- postgres18- auth19- realtime20- storage21version: 1.0.022category: development23metadata:24 source: https://skillmd.com/skills/oyi77/supabase-patterns25---26272829## Overview3031Supabase-specific patterns for building secure, real-time applications. Covers RLS policies, edge functions, real-time, storage, and auth.3233## Capabilities3435- Implement Row Level Security (RLS) for multi-tenant data36- Write Supabase Edge Functions for serverless logic37- Set up real-time subscriptions for live data38- Integrate Supabase Auth with social providers39- Use Supabase Storage for file uploads4041## When to Use42**Trigger phrases:**43- "supabase patterns"44- "Supabase patterns — Row Level Security, edge functions, real-time subscriptions,"454647- Building multi-tenant SaaS with Supabase48- Need real-time features (live updates, presence)49- Serverless backend with Edge Functions50- File storage and CDN for user uploads5152## When NOT to Use5354- Task is about deployment, not development (use deploy skills)55- Task is about code review, not writing (use review skills)56- You need to understand existing code first (use research skills)57- Task is about testing only (use test skills)58- Requirements are unclear (clarify first)59- Task is trivially simple (single line fix)606162## Pseudo Code6364The supabase-patterns workflow follows a standard pipeline pattern.6566Core flow:67```68# supabase-patterns primary flow69input = prepare(raw_data)70result = process(input, config={auth, edge, functions, integration, level})71validate(result)72deliver(result)73```7475Error handling:76```77on error:78 log(error_details)79 retry_with_backoff(max=3)80 if still_failing: alert_and_escalate()81```828384### Row Level Security85```sql86-- Users can only see their own data87CREATE POLICY "users_own_data" ON orders88 FOR ALL USING (auth.uid() = user_id);8990-- Team members can see team data91CREATE POLICY "team_access" ON projects92 FOR SELECT USING (93 team_id IN (SELECT team_id FROM team_members WHERE user_id = auth.uid())94 );95```9697### Edge Function98```typescript99// supabase/functions/hello/index.ts100Deno.serve(async (req) => {101 const { name } = await req.json()102 const supabase = createClient(103 Deno.env.get('SUPABASE_URL')!,104 Deno.env.get('SUPABASE_ANON_KEY')!105 )106 const { data } = await supabase.from('greetings').insert({ name })107 return new Response(JSON.stringify(data))108})109```110111### Real-time Subscription112```typescript113const channel = supabase114 .channel('orders')115 .on('postgres_changes', { event: '*', schema: 'public', table: 'orders' }, handleUpdate)116 .subscribe()117```118119## Common Patterns120121- **RLS always on**: Enable RLS on every table — no exceptions122- **Edge Functions for webhooks**: Process Stripe, email events serverlessly123- **Real-time for collaboration**: Use presence and broadcast for multi-user features124125126## Setup and Configuration127128### Project Setup1291301. **Create a Supabase project** — Start a new project in the Supabase dashboard, then copy the project URL and anon key.1312. **Install the SDK** — `npm install @supabase/supabase-js`1323. **Configure auth** — Enable email/password, OAuth providers (Google, GitHub), or magic links in the Supabase dashboard.1334. **Define schema** — Create tables, enable Row Level Security, write RLS policies, set up triggers.1345. **Build queries** — Use the Supabase client for select, insert, update, delete with chained filters.1356. **Add real-time** — Subscribe to table changes with Supabase Realtime channels.136137### Client Initialization138139```typescript140import { createClient } from '@supabase/supabase-js';141142const supabase = createClient(process.env.SUPABASE_URL, process.env.SUPABASE_ANON_KEY);143```144145### Auth Example146147```typescript148const { data: { user } } = await supabase.auth.signUp({149 email: 'user@example.com',150 password: 'password123',151});152```153154### Query with Joins155156```typescript157const { data: posts } = await supabase158 .from('posts')159 .select('*, author:profiles(*)')160 .eq('status', 'published')161 .order('created_at', { ascending: false });162```163164## How to Use1651661. Understand the requirement and existing codebase patterns1672. Design the solution with error handling and testability in mind1683. Implement incrementally with tests for each change1694. Verify against expected outcomes (manual and automated)1705. Document usage, edge cases, and integration points1716. Review with team before merging to shared branches172173## Red Flags174175- **Skipping tests to ship faster**: Untested code breaks in production when you least expect it176- **No error handling in production code**: Unhandled errors crash services and lose user data177- **Hardcoded configuration values**: Hardcoded values prevent environment switching and leak secrets178- **Ignoring security implications**: Missing input validation, auth bypasses, and injection vulnerabilities179- **Over-engineering simple solutions**: Premature abstraction adds complexity without proportional benefit180181## Verification182183- [ ] Skill output matches expected behavior184- [ ] Auth flow works (signup, login, logout)185- [ ] RLS policies enforce access control186- [ ] Queries return correct data187- [ ] Real-time subscriptions fire on changes188189## Process1901911. Analyze the task requirements1922. Apply domain expertise1933. Verify output quality194195## Anti-Rationalization Table196197| Rationalization | Reality |198|---|---|199| "Tests slow me down" | Bugs slow you down 10x more. Tests are speed, not overhead. |200| "I will refactor later" | Technical debt compounds. Refactor as you go. |201| "It works on my machine" | If it is not in CI, it does not work. Ship proof, not claims. |202| "RLS is optional" | Without RLS, any authenticated user can access any data. |203| "I will add auth later" | Retrofitting auth is 10x harder than building with it from day one. |