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 JWT (JSON Web Token) authentication powered by Supabase Auth. All API endpoints (except/health and /api/test) require a valid JWT token in the Authorization header.
Getting a JWT Token
Tokens are obtained through Supabase Auth authentication flows:1. Sign In
Users authenticate via the frontend application, which uses Supabase Auth with PKCE flow:- Email/Password: Traditional email and password authentication
- OAuth Providers: Google OAuth (additional providers can be configured)
2. Frontend Token Retrieval
In the frontend application, tokens are automatically retrieved and attached to requests using thesecureFetch() utility:
secureFetch() function (from src/lib/fetch.ts) automatically:
- Retrieves the current Supabase session
- Extracts the
access_token - Adds it to the
Authorizationheader
Authorization Header Format
Include the JWT token in theAuthorization header using the Bearer scheme:
Example Request
Token Validation
The API validates tokens using Supabase Auth’sgetUser() method:
- Extract Token: The server extracts the Bearer token from the
Authorizationheader - Validate with Supabase: Token is validated against Supabase Auth
- Verify User: User information is extracted from the validated token
- Attach to Request: User data is attached to
req.userfor downstream handlers
Server-Side Implementation
Fromserver.js:server.js:208-243:
Token Lifecycle
JWT tokens expire after a configurable period (default: 1 hour). The frontend automatically handles token refresh using Supabase’s session management.
When a token expires, Supabase automatically attempts to refresh it using the refresh token stored in the session. This happens transparently in the frontend.
Tokens are immediately invalidated when a user signs out. The Supabase session is cleared, and subsequent API requests with the old token will fail with 401 Unauthorized.
Local Admin Bypass (Development Only)
For local development and testing, SubPirate Pro includes an admin bypass mechanism that allows API access without a Supabase session.Enabling Local Admin Mode
Set these environment variables:VITE_ prefixes for frontend access:
How It Works
-
Frontend: When enabled,
secureFetch()uses the local admin token instead of retrieving a Supabase session: -
Backend: The server recognizes the local admin token and creates a synthetic admin user:
-
Database Access: Local admin requests use the Supabase service role client, which bypasses Row Level Security (RLS) policies:
Security Safeguards
The server explicitly ignores
LOCAL_ADMIN_BYPASS=1 in production:Even with local admin enabled, requests must come from allowed CORS origins (defaults to localhost/127.0.0.1 in dev).
Example Usage
Authentication Errors
Missing Token
401 Unauthorized
Cause: No Authorization header present in the request
Solution: Include the Bearer token in the header
Invalid or Expired Token
401 Unauthorized
Cause: Token is malformed, expired, or revoked
Solution: Obtain a fresh token by re-authenticating
Configuration Error
500 Internal Server Error
Cause: Server environment variables are not configured
Solution: Ensure SUPABASE_URL and SUPABASE_ANON_KEY are set on the server
User Context
Once authenticated, user information is available in the request context:Unique user ID (UUID format)
User’s email address
The JWT access token used for the request
true if using local admin bypass (development only)