---
name: "supabase-auth-row-level-security"
description: "Enforce zero-trust multi-tenant data access policies at the database layer with Supabase and RLS."
metadata:
  author: "Supabase"
  version: "1.0.0"
  runtime_compatibility:
    - "codex"
    - "claude-code"
    - "cursor"
    - "windsurf"
triggers:
  - "write postgres rls policy supabase"
  - "setup @supabase/ssr nextjs"
  - "auth.uid() rls rule"
permissions:
  fs_read: true
  fs_write: "workspace"
  shell_exec: false
  net_access: false
---

# Supabase Client & PostgreSQL Row Level Security (RLS)

Configures Supabase in Next.js/Vue: @supabase/ssr package, cookie storage helpers, authoring PostgreSQL Row Level Security policies (CREATE POLICY ... USING (auth.uid() = user_id)), and auth state listeners.

## When to Invoke
Invoke this skill whenever you need to:
- write postgres rls policy supabase
- setup @supabase/ssr nextjs
- auth.uid() rls rule

## Execution SOP & Rules
1. Enable RLS on table: ALTER TABLE documents ENABLE ROW LEVEL SECURITY;.
2. Create policy: CREATE POLICY 'Users view own docs' ON documents FOR SELECT USING (auth.uid() = user_id);.
3. Initialize SSR client: createServerClient(url, key, { cookies: { get, set, remove } }).
4. Verify unauthorized users receive empty result sets without leaking data even if frontend guards are bypassed.

## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.
