Server-Side Rendering (SSR)
Integrate Crossmint Auth on the server-side for user authentication and management
Crossmint Auth provides a flexible and simple authentication solution for your crypto server-side applications. This guide covers how to integrate and use Crossmint Auth across various server-side frameworks.
Overview
Our server SDK allows you to:
- Manage user sessions
- Retrieve user profiles
- Verify JSON Web Tokens (JWTs)
Installation
First, install the Crossmint Server SDK:
Initialization
To use Crossmint Auth, you need to initialize it with your Server API key. This API requires the users.read
scope.
Core Functionality
Session Management
The getSession
method validates or refreshes a user’s session based on their JWT and refresh token.
This method:
- Fetches the current JWT and refresh token from the cookies with keys
crossmint-jwt
andcrossmint-refresh-token
. - Checks if the current JWT is valid
- Refreshes the session if needed
- Stores the new JWT and refresh token in cookies
- Returns new auth materials and the user ID
For other frameworks that do not expose standard request and response objects, such as Next.js using the App Router, you can pass in an object with jwt
and refreshToken
properties instead:
User Profile Retrieval
Fetch user details using the getUser
method:
This provides access to user information such as email, phone number, and connected accounts (e.g., Google, Farcaster).
JWT Verification
Verify JWTs independently using the verifyCrossmintJwt
method:
This is useful for validating tokens in middleware or specific endpoints. We expose our public keys for this purpose at https://www.crossmint.com/.well-known/jwks.json.