Supabase
Set up authentication and database with Supabase.
Supabase provides authentication and a Postgres database with Row Level Security.
Create a Project
- Go to supabase.com and create an account
- Create a new project
- Wait for the project to be provisioned (takes ~2 minutes)
Get Your API Keys
Navigate to Settings → API in your Supabase dashboard and copy:
| Key | Environment Variable |
|---|---|
| Project URL | NEXT_PUBLIC_SUPABASE_URL |
| Anon/Public key | NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY |
| Service role key | SUPABASE_SECRET_KEY |
Never expose the service role key on the client. It bypasses Row Level Security.
Run Database Migrations
Option 1: Supabase Dashboard
- Go to SQL Editor in your Supabase dashboard
- Open
supabase/migrations/001_initial.sqlfrom your project - Paste the contents and run the query
Option 2: Supabase CLI (Recommended)
# Link to your remote project
pnpm supabase link --project-ref <your-project-ref>
# Push migrations
pnpm supabase:push
Local Development
For local development, you can run Supabase locally:
# Start local Supabase (requires Docker)
pnpm supabase:start
# Stop when done
pnpm supabase:stop
# Reset database and run migrations
pnpm supabase:reset
Local Supabase runs at http://localhost:54321 with a dashboard at http://localhost:54323.
Row Level Security
VelocityKit uses account-scoped data access. All tables with user data have RLS policies.
Key principle: Data is scoped to account_id, not user_id. This allows for future team/organization features without migrations.
Example policy:
CREATE POLICY "Users can view their account's data"
ON items FOR SELECT
USING (account_id IN (
SELECT account_id FROM account_users WHERE user_id = auth.uid()
));
Authentication Flow
- User signs up → Supabase creates auth user
- Trigger creates profile and account records
- User signs in → Session stored in cookies
- Auth proxy refreshes sessions automatically
Supported Auth Methods
- Email/password (default)
- Social login (Google, GitHub, etc.)
- Magic links
- MFA (optional)
To enable social providers, configure them in Authentication → Providers in your Supabase dashboard.
Generate TypeScript Types
After changing your database schema:
pnpm supabase:types
This generates types in src/types/supabase.ts for full type safety.