The Crossmint Server SDK automatically manages user sessions by validating JWT tokens and refreshing them when they expire.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Crossmint/crossmint-sdk/llms.txt
Use this file to discover all available pages before exploring further.
How Session Validation Works
When you callgetSession(), the SDK performs the following steps:
Retrieve authentication material
The SDK extracts the JWT and refresh token from cookies or the provided request object.
Refresh if needed
If the JWT is expired or invalid, the SDK automatically uses the refresh token to obtain a new JWT.
CrossmintAuthServer.ts:166
Session Validation
Basic Session Validation
ThegetSession() method automatically validates and refreshes sessions:
jwt- The validated (or refreshed) JWT tokenuserId- The user’s unique identifierrefreshToken- The refresh token object withsecretandexpiresAt
Validation Without Auto-Refresh
If you want to validate a JWT without automatic refresh, useverifyCrossmintJwt():
Token Refresh
Automatic Token Refresh
The SDK automatically refreshes expired tokens when callinggetSession(). No additional code is required:
Manual Token Refresh
You can manually refresh tokens using thehandleCustomRefresh() method. This is useful for setting up custom refresh endpoints.
README.md:89
Logout
Thelogout() method clears authentication material from cookies and optionally calls the Crossmint logout endpoint.
Logout in Fetch API Environments
Next.js
README.md:120
Logout in Node.js API Environments
Express
README.md:126
What Happens During Logout
Call logout endpoint
The SDK calls the Crossmint logout endpoint to invalidate the refresh token (if possible).
Clear cookies
Authentication cookies are cleared by setting them to empty values with past expiration dates.
CrossmintAuthServer.ts:141
Cookie Names
The SDK uses the following cookie names by default:crossmint-session- Stores the JWT token (not HttpOnly, accessible to the client SDK)crossmint-refresh-token- Stores the refresh token (can be HttpOnly for security)
Session Error Handling
When session validation or refresh fails, the SDK:- Throws a
CrossmintAuthenticationError - Automatically clears cookies if a response object is provided
- Logs the error to the console
Complete Example: Protected Route
Next Steps
Custom Refresh Routes
Set up custom refresh routes for enhanced security with HttpOnly cookies