This SDK provides a set of tools for authenticating users in a Crossmint-powered application using server-side rendering (SSR). It simplifies the process of handling authentication tokens and managing user sessions, making it easier to integrate authentication into your Next.js applications.
To install the SDK, you can use npm or yarn:
npm install @crossmint/server-sdk
To use the SDK in your application, follow these steps:
- Import the SDK into your project:
import { createCrossmint, CrossmintAuth } from "@crossmint/server-sdk";
const crossmint = createCrossmint({
apiKey: process.env.SERVER_CROSSMINT_API_KEY || "",
});
const crossmintAuth = CrossmintAuth.from(crossmint);
- Use the SDK to authenticate users:
With most frameworks, pass the request object:
const { jwt, userId } = await crossmintAuth.getSession(request);
With Next.js, fetch the cookies and pass them to the getSession
method:
import { cookies } from "next/headers";
const cookieStore = cookies();
const jwtCookie = cookieStore.get("crossmint-session")?.value;
const refreshCookie = cookieStore.get("crossmint-refresh-token")?.value;
const { jwt, userId } = await crossmintAuth.getSession({
jwt: jwtCookie,
refreshToken: refreshCookie,
});