IncomingMessage/ServerResponse)
and Fetch API (Request/Response) request/response objects.
Create an instance with CrossmintAuthServer.from and a server-side API key. Sessions, refreshes and
logout need no API key scope; CrossmintAuthServer.getUser needs users.read.
Extends
CrossmintAuth
Methods
getJwksUri()
getJwksUri(): string
Defined in: packages/common/auth/dist/CrossmintAuth.d.ts:19
Returns
string
Inherited from
CrossmintAuth.getJwksUri
getSession()
getSession(Defined in: packages/server/src/auth/CrossmintAuthServer.ts:72 Validate the user’s session and return it, refreshing it if expired. Accepts either a request object (auth material is read from cookies) or the auth material itself (options,response?):Promise<AuthSession>
{ jwt, refreshToken }). From a request, the cookies are read under the project-scoped
names the client SDK writes (see getAuthCookieNames), falling back to
the legacy crossmint-jwt / crossmint-refresh-token names. If a response object is provided,
refreshed auth material is stored in its cookies. When the session was refreshed, the result also
holds the user (email, phone number, linked accounts), so no getUser call is needed.
Parameters
Returns
Promise<AuthSession>
Throws
CrossmintAuthenticationError if no valid session can be established.getUser()
getUser(Defined in: packages/server/src/auth/CrossmintAuthServer.ts:106 Fetch the user with the given ID (theexternalUserId):Promise<SDKExternalUser>
userId from CrossmintAuthServer.getSession, the JWT’s sub).
Needs a server API key with the users.read scope.
Parameters
Returns
Promise<SDKExternalUser>
Throws
CrossmintAuthenticationError with the HTTPstatus if Crossmint rejects the request, for example
403 when the API key lacks the users.read scope or 404 when the user has not signed in to this project.
Throws
ApiClientError on a 5xx response, as every Crossmint API call does.handleCustomRefresh()
handleCustomRefresh(Defined in: packages/server/src/auth/CrossmintAuthServer.ts:128 Handle a token refresh request on a custom refresh route. Reads the refresh token from the request body or cookies, refreshes the session, and returns a response with the new auth material stored in cookies. Returns a 401 response if the refresh fails.request,response?):Promise<GenericResponse>
Parameters
Returns
Promise<GenericResponse>
logout()
logout(Defined in: packages/server/src/auth/CrossmintAuthServer.ts:204 Log the user out: invalidate the refresh token with Crossmint and clear the auth cookies on the response.request?,response?):Promise<GenericResponse>
Parameters
Returns
Promise<GenericResponse>
storeAuthMaterial()
storeAuthMaterial(Defined in: packages/server/src/auth/CrossmintAuthServer.ts:199 Store auth material (JWT and refresh token) in the response’s cookies, under the project-scoped names. Empty auth material (logout) also expires the legacy unscoped cookies.response,authMaterial):void
Parameters
Returns
void
verifyCrossmintJwt()
verifyCrossmintJwt(Defined in: packages/server/src/auth/CrossmintAuthServer.ts:188 Verify a Crossmint-issued JWT and return its decoded payload — checks the signature, expiry, and that it was issued for this project (token,jwks?):Promise<JWTPayload>
aud matches the API key’s project ID).
Uses Crossmint’s JWKS endpoint unless a key set is provided.
Parameters
Returns
Promise<JWTPayload>
defaultApiClient()
Defined in: packages/common/auth/dist/CrossmintAuth.d.ts:24staticdefaultApiClient(crossmint):CrossmintApiClient
Parameters
Returns
CrossmintApiClient
Inherited from
CrossmintAuth.defaultApiClient
from()
Defined in: packages/server/src/auth/CrossmintAuthServer.ts:57 Create astaticfrom(crossmint,options):CrossmintAuthServer
CrossmintAuth instance from a Crossmint object (created with createCrossmint).
Parameters
Returns
CrossmintAuthServer
Overrides
CrossmintAuth.from
