@crossmint/server-sdk
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

@crossmint/server-sdk

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.

Installation

To install the SDK, you can use npm or yarn:

npm install @crossmint/server-sdk

Usage

To use the SDK in your application, follow these steps:

  1. 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);
  1. 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,
});

Dependencies (4)

Dev Dependencies (1)

Package Sidebar

Install

npm i @crossmint/server-sdk

Weekly Downloads

16

Version

1.0.2

License

Apache-2.0

Unpacked Size

65.7 kB

Total Files

75

Last publish

Collaborators

  • devlyn-paella
  • manishpaella
  • alberto-crossmint
  • afeight
  • pegidopaella
  • pascualino
  • alfonso_paella
  • maxwellfortney