Documentation Index
Fetch the complete documentation index at: https://mintlify.com/MatthewSabia1/SubPirate-Pro/llms.txt
Use this file to discover all available pages before exploring further.
Overview
SubPirate Pro uses Supabase for:- Authentication: Email/password and Google OAuth with PKCE flow
- Database: PostgreSQL with extensive Row-Level Security (RLS) policies
- Storage: Profile images and campaign media
supabase/migrations/ and uses RLS extensively to ensure data security.
Prerequisites
- Supabase account (free tier available)
- Supabase CLI v2.33.9 (for local development)
- Docker (for local Supabase)
Creating a Supabase Project
Create new project
- Go to supabase.com/dashboard
- Click “New Project”
- Enter project details:
- Name: SubPirate Pro
- Database Password: Generate a strong password
- Region: Choose closest to your users
- Pricing Plan: Start with Free tier
- Wait for project provisioning (2-3 minutes)
Get API credentials
Navigate to Project Settings → API:
- Project URL: Your Supabase project URL
- anon/public key: Safe for browser use
- service_role key: Server-only, never expose to browser
Link local project
Link your local repository to the Supabase project:The project ref is in your Project URL:
https://<project-ref>.supabase.coAuthentication Configuration
Email Authentication
Configure site URLs
Go to Authentication → URL Configuration:
- Site URL:
https://your-domain.com - Redirect URLs: Add the following:
https://your-domain.com/auth/callbackhttps://your-domain.com/auth/reset-passwordhttp://localhost:5173/auth/callback(for local dev)http://localhost:5173/auth/reset-password(for local dev)
Google OAuth (Optional)
Create Google OAuth credentials
- Go to Google Cloud Console
- Create a new project or select existing
- Enable Google+ API
- Go to Credentials → Create Credentials → OAuth client ID
- Choose Web application
- Add authorized redirect URIs:
https://<your-project-ref>.supabase.co/auth/v1/callback
- Copy Client ID and Client Secret
Database Schema
Core Tables
SubPirate Pro’s schema includes the following key tables:Users & Profiles
profiles: User profiles (auto-created on signup via trigger)- One-to-one with
auth.users - Stores display name and profile image
- RLS: Users can only select/update their own profile
- One-to-one with
Reddit Integration
reddit_accounts: Connected Reddit accounts- Links to
profilesviauser_id - Stores account metadata (username, karma, created date)
- Links to
reddit_account_tokens: Encrypted OAuth tokens- Encrypted with AES-256-GCM using
TOKEN_ENCRYPTION_KEY - RLS: Tokens only accessible via service role (server-side)
- Encrypted with AES-256-GCM using
Projects & Organization
projects: User-created project containersproject_members: Team collaboration with roles (read/edit/owner)project_subreddits: Subreddits organized into projects
Subreddit Analysis
subreddits: Cached subreddit metadatasubreddit_analyses: LLM-generated marketing analysisanalysis_locks: Prevents duplicate concurrent analyses
Campaign System
campaigns: Posting campaigns with schedulingcampaign_members: Role-based campaign accesscampaign_content_versions: Version-controlled post contentcampaign_runs: Execution historycampaign_run_attempts: Individual post attempts with results
Row-Level Security (RLS)
Every table has RLS enabled with granular policies:RLS policies ensure users can only access their own data and data explicitly shared with them via project/campaign membership.
Auto-Generated Profile
New users automatically get a profile via trigger:Schema Migrations
Migrations live insupabase/migrations/ and are applied in order:
Applying Migrations
- Hosted Supabase
- Local Supabase
Push migrations to your hosted project:This applies all unapplied migrations.
Creating New Migrations
To create a new migration:supabase/migrations/ with a timestamp prefix.
Type Generation
Generate TypeScript types from your database schema:- From Hosted Project
- From Local Project
Storage Configuration
Configure storage buckets for user uploads:Create storage buckets
Go to Storage in Supabase dashboard:
-
Create bucket:
profile-images- Public: ✓ Enabled
- File size limit: 2MB
- Allowed MIME types:
image/jpeg,image/png,image/webp
-
Create bucket:
campaign-media- Public: ✓ Enabled
- File size limit: 10MB
- Allowed MIME types:
image/jpeg,image/png,image/webp,image/gif,video/mp4
Local Development
Starting Local Supabase
Run a complete local Supabase stack with Docker:- PostgreSQL database (port 54322)
- API gateway (port 54321)
- Studio UI (port 54323)
- Inbucket email server (port 54324)
- Edge Functions runtime (port 54321)
Viewing Local Services
After starting, access:- Supabase Studio:
http://127.0.0.1:54323 - API:
http://127.0.0.1:54321 - Email inbox:
http://127.0.0.1:54324(view auth emails)
Resetting Local Database
Reset to a clean state matching migrations:Linting Schema
Check for common schema issues:- RLS policies on all tables
- Index coverage for foreign keys
- Function security settings
Environment Variables
For Application
Set these in your.env file:
For Supabase CLI
Optionally set for CLI commands:Security Best Practices
Row-Level Security
Always enable RLS
Always enable RLS
Every table must have RLS enabled:Without RLS, tables are accessible by anyone with the anon key.
Use auth.uid() for ownership
Use auth.uid() for ownership
Filter by authenticated user:
Test RLS policies
Test RLS policies
Verify policies work as expected:
Use security definer carefully
Use security definer carefully
Functions marked Always set
security definer run with creator’s privileges:search_path to prevent attacks.Token Security
- anon key: Safe for browser, respects RLS
- service_role key: Server-only, bypasses RLS, never expose
- Refresh tokens: SubPirate stores Reddit refresh tokens encrypted with AES-256-GCM
Authentication Security
- Enable email confirmation in production
- Use PKCE flow for OAuth (already configured)
- Set appropriate session timeouts
- Configure password strength requirements
Monitoring & Maintenance
Database Stats
View database statistics in Database → Statistics:- Table sizes
- Index usage
- Query performance
- Connection pool status
Logs
View logs in Logs → Postgres Logs:- Slow queries (>1s)
- Connection errors
- RLS policy violations
- Function errors
Backups
Supabase provides automatic backups on paid plans:- Free: Daily backups (7 day retention)
- Pro: Daily backups (30 day retention)
- Team/Enterprise: Configurable retention
Troubleshooting
RLS policy errors
Problem: Queries fail with “new row violates row-level security policy” Solution:- Check which policy is failing
- Verify
auth.uid()returns expected user ID - Test policy with direct SQL
- Ensure
with checkclause allows the operation
Migration conflicts
Problem:supabase db push fails with conflict errors
Solution:
- Check migration history:
supabase migration list - Repair if needed:
supabase migration repair --status applied <version> - Or reset:
supabase db reset --local --yes(local only)
Connection issues
Problem: Cannot connect to Supabase Solution:- Verify project is not paused (free tier pauses after inactivity)
- Check API credentials are correct
- Test with curl:
curl https://your-project.supabase.co/rest/v1/ - Check Supabase status page:
status.supabase.com
Type generation failures
Problem:supabase gen types fails
Solution:
- Ensure migrations are applied:
supabase db push - Check for syntax errors in migrations
- Verify CLI version:
supabase --version(use v2.33.9)
Next Steps
Local Development
Set up local environment
Vercel Deployment
Deploy to production