Authentication
Overview
The Form Platform uses Stytch for user authentication in the dashboard and API keys for programmatic access.
Authentication Methods
1. Stytch Session Authentication (Dashboard)
Used For: Dashboard UI access
Flow:
User logs in via Stytch
Stytch returns session token
Token stored in cookies/localStorage
Token included in API requests
Implementation:
Next.js Stytch SDK
Session management via cookies
Automatic token refresh
Protected route groups
2. API Key Authentication (Programmatic)
Used For: Server-side API access
Key Types:
Secret Keys:
sk_live_...orsk-live-...(legacy)Publishable Keys:
pk-live-...(optional, for public forms)
Usage:
Authorization: Bearer sk_live_...Stytch Integration
Dashboard Authentication
Login Flow:
User visits
/loginStytch authentication UI
User authenticates (email, OAuth, etc.)
Session created
Redirect to dashboard
Session Management:
Session stored in cookies
Automatic refresh
Logout revokes session
User Resolution
Flow:
Session token extracted from request
Stytch API validates token
User data retrieved
Remote user record created/updated
User context available in app
API Key Authentication
Secret Keys
Generation:
Created via API or dashboard
KMS-encrypted storage
Hashed for fast lookup
One active key per user/environment
Validation:
Lambda authorizer validates key
Hash-based lookup (O(1))
Returns user ID and environment
IAM policy generated
Publishable Keys
Usage:
Optional for public form submissions
No authentication required
Rate limited by IP
Format:
pk-live-...
Authorization
User Ownership
Resources are scoped by user:
Forms belong to users
Submissions belong to form owners
API keys belong to users
Environment Scoping
All resources are environment-scoped:
Forms in specific environments
API keys per environment
Queries filtered by environment
Session Management
Token Extraction
From Headers:
const authHeader = headers.authorization;
const token = authHeader?.startsWith('Bearer ')
? authHeader.substring(7)
: null;From Cookies:
const cookies = parseCookies(cookieHeader);
const token = cookies['stytch_session'];Token Validation
Stytch Validation:
const session = await stytchClient.sessions.authenticate({
session_token: token
});Next Steps
Authorization - Authorization details
Security - Security best practices
Last updated