Status: built (2026-10-05). Tests: packages/server/tests/server.test.ts (a Hono app and a Node http server against the real broker), plus the Next.js SDK's own, which now sits on this package.
Next.js has its own SDK (INTEGRATION.md). Everything else — Hono, Express, SvelteKit, Remix / React Router, Astro, Nuxt, Cloudflare Workers, Deno,
Bun — uses @passkin/server: the same sign-in handlers, the same encrypted session cookie, and token verification, written against the web's Request and Response
so they run unchanged anywhere. (Any OpenID Connect library works too; this is the same thing with the PKCE, state, nonce, cookie and refresh-token details done for you.)
// passkin.ts
import { createPasskinServer } from "@passkin/server";
export const passkin = createPasskinServer(); // PASSKIN_PUBLISHABLE_KEY, PASSKIN_COOKIE_SECRET (32+ random characters), PASSKIN_URL, PASSKIN_APP_URL
Register http://localhost:3000/api/auth/callback (your origin + /api/auth/callback) as a redirect address of your project, then do three things:
- Mount the sign-in routes at
/api/auth/*for every method:passkin.handle(request)answerssignin,callback,signout(POST),session,organizationand the/api/auth/api/me/…proxy the React components use. - Read the person:
const { session, setCookie } = await passkin.getSession(request);session.user,session.userId,session.accessToken. SendsetCookieon your response (passkin.withCookies(response, setCookie)): when the access token was about to expire it was refreshed, the refresh token rotated, and the browser must receive the new cookie. - Guard a page:
const gate = await passkin.protect(request); if ("response" in gate) return gate.response;— a signed-out visitor is redirected to sign in and back.
For an API your own apps (iOS, Android, a single-page app) call with their access token: const caller = await passkin.verifyRequest(request) → { userId, clientId, scopes } or null.
To protect an API or MCP server for third parties, see createResourceServer in OAUTH.md (also exported here).
Hono / Cloudflare Workers / Deno / Bun
import { Hono } from "hono";
import { passkin } from "./passkin";
const app = new Hono();
app.all("/api/auth/*", (c) => passkin.handle(c.req.raw));
app.get("/dashboard", async (c) => {
const gate = await passkin.protect(c.req.raw);
if ("response" in gate) return gate.response;
return passkin.withCookies(c.json({ hello: gate.session.user.email }), gate.setCookie);
});
export default app;
On Workers pass the settings explicitly (createPasskinServer({ publishableKey: env.PASSKIN_PUBLISHABLE_KEY, cookieSecret: env.PASSKIN_COOKIE_SECRET, … })) inside the handler, or once per isolate.
Express / Fastify / Koa (Node http)
import { toWebRequest, sendWebResponse } from "@passkin/server/node";
const ORIGIN = process.env.PASSKIN_APP_URL!; // https://app.example.com
app.all("/api/auth/*", async (req, res) => sendWebResponse(res, await passkin.handle(await toWebRequest(req, ORIGIN))));
app.get("/dashboard", async (req, res) => {
const gate = await passkin.protect(await toWebRequest(req, ORIGIN));
if ("response" in gate) return sendWebResponse(res, gate.response);
res.setHeader("Set-Cookie", gate.setCookie);
res.json({ hello: gate.session.user.email });
});
toWebRequest uses req.originalUrl (Express mounts) and the body a parser already read; sendWebResponse writes every Set-Cookie separately.
SvelteKit
// src/hooks.server.ts
import { passkin } from "$lib/passkin";
export const handle = async ({ event, resolve }) => {
if (event.url.pathname.startsWith("/api/auth/")) return passkin.handle(event.request);
const { session, setCookie } = await passkin.getSession(event.request);
event.locals.user = session?.user ?? null;
return passkin.withCookies(await resolve(event), setCookie);
};
Remix / React Router (framework mode)
// app/routes/api.auth.$.ts
export const loader = ({ request }) => passkin.handle(request);
export const action = ({ request }) => passkin.handle(request);
// in any loader
const gate = await passkin.protect(request);
if ("response" in gate) throw gate.response;
return data({ user: gate.session.user }, { headers: gate.setCookie.map((c) => ["Set-Cookie", c]) });
Astro
// src/pages/api/auth/[...passkin].ts
export const ALL = ({ request }) => passkin.handle(request);
// src/middleware.ts
export const onRequest = async ({ request, locals }, next) => {
const { session, setCookie } = await passkin.getSession(request);
locals.user = session?.user ?? null;
return passkin.withCookies(await next(), setCookie);
};
Nuxt (Nitro)
// server/routes/api/auth/[...passkin].ts
export default defineEventHandler((event) => passkin.handle(toWebRequest(event)));
What it does for you
- PKCE (S256), state, nonce and
isson every sign-in; the return address is only ever a path on your site (never//evil.com). - The session cookie is encrypted and authenticated (
HttpOnly,SameSite=Lax,Secureover https); the tokens never reach the browser's JavaScript. - Refresh tokens rotate; a session ended or banned at Passkin is signed out here at the next refresh; sign-out revokes the refresh token at Passkin, so the tokens stop everywhere.
- State-changing requests (sign-out, the
meproxy, organization switching) must come from your own origin.
Not built yet
A Passkin CLI recipe for these frameworks (passkin init knows Next.js only); Vue- and Svelte-specific component wrappers (the web components in ELEMENTS.md work in both); a single-page-app-only (no server) client; Edge middleware helpers other than Next.js's.