
Product
Socket Now Supports pylock.toml Files
Socket now supports pylock.toml, enabling secure, reproducible Python builds with advanced scanning and full alignment with PEP 751's new standard.
@crossmint/server-sdk
Advanced tools
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 authentic
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 { createCrossmint, CrossmintAuth } from "@crossmint/server-sdk";
const crossmint = createCrossmint({
apiKey: process.env.SERVER_CROSSMINT_API_KEY || "",
});
const crossmintAuth = CrossmintAuth.from(crossmint);
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,
});
If you are using a framework with access to the response object, you can store the authentication material in cookies by passing the response object to the getSession
method:
const { jwt, userId } = await crossmintAuth.getSession(request, response);
await crossmintAuth.logout(request);
The SDK allows you to set the httpOnly
, secure
, domain
and sameSite
options for the cookies. This way, you can control how the cookies are stored and transmitted. Putting this together with a custom refresh route, you can store the authentication material in HttpOnly cookies that are tied to the domain of the provided route.
Configure CrossmintAuth to do so when creating the custom refresh route:
const crossmintAuth = CrossmintAuth.from(crossmint, {
cookieOptions: {
httpOnly: true,
sameSite: "Strict",
secure: true,
domain: ".example.com",
},
});
httpOnly
only applies to the refresh token. The session token will not be HttpOnly as it is used in the client for API calls.
To set up a custom refresh route, you can use the handleCustomRefresh
method. This method will refresh the token and return the new authentication material. This way, the authentication material can be stored in cookies that are tied to the domain of the provided route.
In environments that use the Fetch API for Request
and Response
objects, handleCustomRefresh
will return the response object:
return await crossmintAuth.handleCustomRefresh(request);
In environments that use Node.js API, you also need to provide the response object and end the response:
await crossmintAuth.handleCustomRefresh(req, res);
res.end();
You can also provide a custom refresh route:
const crossmintAuth = CrossmintAuthClient.from(crossmint, {
refreshRoute: "/api/refresh",
});
This way, the SDK will use the provided route to refresh the token instead of the default one and the authentication material can be stored in HttpOnly cookies that are tied to the domain of the provided route.
When using HttpOnly
cookies, logout can't happen client-side as it doesn't have access to the cookies. You can set up a custom logout route to handle the logout process.
In environments that use the Fetch API, logout
will return the response object:
return await crossmintAuth.logout(request);
In environments that use Node.js API, you also need to provide the response object and end the response:
await crossmintAuth.logout(req, res);
res.end();
FAQs
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 authentic
The npm package @crossmint/server-sdk receives a total of 684 weekly downloads. As such, @crossmint/server-sdk popularity was classified as not popular.
We found that @crossmint/server-sdk demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports pylock.toml, enabling secure, reproducible Python builds with advanced scanning and full alignment with PEP 751's new standard.
Security News
Research
Socket uncovered two npm packages that register hidden HTTP endpoints to delete all files on command.
Research
Security News
Malicious Ruby gems typosquat Fastlane plugins to steal Telegram bot tokens, messages, and files, exploiting demand after Vietnam’s Telegram ban.