Skip to main content
Defined in: packages/server/src/auth/CrossmintAuthServer.ts:42 Server-side Crossmint authentication client: validate sessions, verify JWTs, refresh tokens, fetch users, and manage auth cookies. Works with both Node.js (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(options, response?): Promise<AuthSession>
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 ({ 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(externalUserId): Promise<SDKExternalUser>
Defined in: packages/server/src/auth/CrossmintAuthServer.ts:106 Fetch the user with the given ID (the 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 HTTP status 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(request, response?): Promise<GenericResponse>
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.

Parameters

Returns

Promise<GenericResponse>

logout()

logout(request?, response?): Promise<GenericResponse>
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.

Parameters

Returns

Promise<GenericResponse>

storeAuthMaterial()

storeAuthMaterial(response, authMaterial): void
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.

Parameters

Returns

void

verifyCrossmintJwt()

verifyCrossmintJwt(token, jwks?): Promise<JWTPayload>
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 (aud matches the API key’s project ID). Uses Crossmint’s JWKS endpoint unless a key set is provided.

Parameters

Returns

Promise<JWTPayload>

defaultApiClient()

static defaultApiClient(crossmint): CrossmintApiClient
Defined in: packages/common/auth/dist/CrossmintAuth.d.ts:24

Parameters

Returns

CrossmintApiClient

Inherited from

CrossmintAuth.defaultApiClient

from()

static from(crossmint, options): CrossmintAuthServer
Defined in: packages/server/src/auth/CrossmintAuthServer.ts:57 Create a CrossmintAuth instance from a Crossmint object (created with createCrossmint).

Parameters

Returns

CrossmintAuthServer

Overrides

CrossmintAuth.from