Endpoint
Request Body
The user ID for whom to create the session. This can be either the primary user ID or recipe user ID depending on your authentication setup.
Custom data to be included in the access token JWT payload. This data is accessible without database queries but increases token size.Example:
Custom data to be stored in the database and associated with the session. This data is not included in tokens.Example:
Whether to enable anti-CSRF token protection for this session. Set to
true for browser-based applications.Whether to use dynamic signing keys for the access token. Defaults to
true for CDI version >= 2.21.true- Uses rotating keys for enhanced securityfalse- Uses static key for simplified verification
Response
Always returns
"OK" on success.Session metadata
Access token information
Refresh token information
ID refresh token (deprecated in CDI >= 2.21)
Anti-CSRF token to be included in subsequent requests (only if
enableAntiCsrf is true).Example Request
Example Response
Implementation Details
Source Code Reference
Implemented in:- API Handler: View source
- Session Logic: View source
Session Creation Process
- Generate Session Handle - Creates a UUID and appends tenant ID if not default
- Handle User ID Mapping - Resolves external user ID to SuperTokens user ID if mapping exists
- Resolve Primary User - Determines primary user ID for linked accounts
- Create Refresh Token - Generates opaque refresh token with optional anti-CSRF
- Create Access Token - Generates JWT with user data and token hashes
- Store in Database - Persists session data with hashed refresh token
- Update Active Users - Records user activity timestamp
Token Expiry
Default token lifetimes (configurable in core config):- Access Token: 1 hour (3600000 ms)
- Refresh Token: 100 days (8640000000 ms)
Security Considerations
User ID Mapping: If using external user ID mapping, provide the external user ID. The core will automatically resolve to the internal SuperTokens user ID.
Error Responses
Error status code
Error description
Common Errors
- 400 Bad Request: Invalid
userDataInJWTpayload that exceeds size limits or contains invalid data - 500 Internal Server Error: Database connection issues or internal processing errors
CDI Version Compatibility
- CDI < 2.21: Returns
idRefreshTokenin response - CDI >= 2.21:
idRefreshTokenremoved,useDynamicSigningKeyparameter available - CDI >= 3.0:
tenantIdincluded in session response - CDI >= 4.0:
recipeUserIdincluded in session response