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 uses Supabase Auth as its authentication layer, implementing modern security best practices including PKCE (Proof Key for Code Exchange) flow, automatic session refresh, and secure profile management.Authentication Architecture
PKCE Flow
All authentication flows use PKCE (RFC 7636) to prevent authorization code interception attacks:Session Management
- Auto-refresh: Access tokens automatically refresh before expiration
- Persistent sessions: Sessions persist across browser restarts using secure
localStorage - Manual code exchange:
detectSessionInUrl: falseprevents race conditions during OAuth callbacks
Supported Authentication Methods
Email/Password Authentication
Sign Up
- Minimum 6-character password requirement
- Email confirmation required (configurable)
- Password reset via secure email link
- Rate limiting on failed attempts
Sign In
formatAuthError() in src/contexts/AuthContext.tsx:76-99).
Google OAuth
Google OAuth uses PKCE flow with offline access for refresh tokens:- User initiates Google OAuth → redirected to Google
- User authorizes → redirected to
/auth/callbackwith authorization code - Client exchanges code for session using PKCE verifier
- Profile auto-created via database trigger
Profile Auto-Creation
User profiles are automatically created on signup via a database trigger:id: UUID matchingauth.users.iddisplay_name: From OAuth metadata or emailimage_url: User avatar (optional)created_at/updated_at: Timestamps
Row-Level Security (RLS)
Profiles are protected by RLS policies ensuring users can only access their own data:All database tables use similar RLS patterns. See Data Encryption for details on encrypted data access.
Password Reset Flow
- User requests password reset
- Secure token sent via email
- User redirected to reset page with token
- New password set via
supabase.auth.updateUser({ password })
Auth State Management
TheAuthContext (src/contexts/AuthContext.tsx) manages authentication state:
Security Headers
All API requests include the application identifier:API Authentication
Server-side API routes verify authentication via JWT:- Frontend attaches JWT via
secureFetch()helper - Server extracts token from
Authorizationheader - Token verified against Supabase (cached for performance)
- User ID available for database queries with RLS context
The JWT contains the user’s
sub (subject) claim, which matches their database UUID. This enables RLS policies to filter data automatically.Development-Only: Local Admin Mode
For local development without Supabase, a bypass mode is available:Best Practices
For Developers
- Never bypass RLS: Always use authenticated Supabase client
- Use
secureFetch(): Don’t manually manage tokens - Handle auth errors gracefully: Display user-friendly messages
- Test auth flows: Verify PKCE, email confirmation, password reset
For Deployment
- Rotate secrets: Change
JWT_SECRETif ever exposed - Enable email confirmation: Prevent fake account creation
- Configure OAuth providers: Use production redirect URLs
- Monitor failed auth attempts: Set up alerts for suspicious activity
Related Documentation
- Data Encryption - Token encryption and key management
- GDPR Compliance - Data access and deletion rights
- API Reference - Auth endpoints