npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@kolaylogin/backend

v0.2.1

Published

Framework-agnostic server-side SDK for KolayLogin: session JWT verify, cookie helpers, webhook signature verification, and Stripe payments client.

Downloads

405

Readme

@kolaylogin/backend

Server-side SDK for verifying KolayLogin sessions in Node.js backends. Built for Express, Fastify, Nest, Koa, Hono, bare http, or anything that exposes a standard cookie header.

What it does

  • Verifies the short-lived __session JWT issued by a KolayLogin instance against its JWKS endpoint.
  • Parses Cookie headers and extracts the session JWT without you having to touch cookie-parsing middleware.
  • Returns fully-typed session claims: sub (user id), sid (session id), env (environment id), plus any custom claims your instance has attached.

It does not perform user creation, password flows, or OAuth redirects — those belong on the instance API and in the browser SDK (@kolaylogin/react, @kolaylogin/nextjs). This package exists so your backend can trust a request without a round-trip to the auth service on every call.

Install

npm install @kolaylogin/backend
# or within the monorepo
npm install -w @kolaylogin/backend

Requires Node 20+.

Quick start

import { KolayLoginBackendClient } from '@kolaylogin/backend';

const kl = new KolayLoginBackendClient({
  baseUrl: process.env.KL_API_BASE_URL!,       // e.g. https://auth.example.com
  issuer: process.env.KL_JWT_ISSUER,           // matches the instance `iss`
  audience: process.env.KL_JWT_AUDIENCE,       // optional
});

// Express
app.get('/api/me', async (req, res) => {
  const session = await kl.getSessionFromRequest(req);
  if (!session) return res.status(401).json({ error: 'unauthenticated' });

  res.json({
    userId: session.sub,
    sessionId: session.sid,
    environment: session.env,
  });
});

The client fetches and caches JWKS the first time you verify a token. JWKS rotation is picked up automatically on cache expiry — you do not need to restart your service after a key rotation on the auth side.

API

new KolayLoginBackendClient(options)

| Option | Type | Required | Description | | ----------- | -------- | -------- | ----------------------------------------------------------------------------- | | baseUrl | string | yes | Instance API base URL. JWKS is discovered at ${baseUrl}/.well-known/jwks.json. | | issuer | string | no | Expected iss claim. Strongly recommended in production. | | audience | string | no | Expected aud claim, if your instance sets it. |

client.verifySessionJwt(token)

Verifies the token against the instance's JWKS and returns the claims. Throws if the token is invalid, expired, or signed by an unknown key.

client.getSessionFromRequest(req)

Pulls the __session cookie out of req.headers.cookie, then verifies it. Returns null when no cookie is present. Throws on an invalid token so your error middleware can decide how to respond.

Low-level helpers

  • parseCookieHeader(header) — returns a plain Record<string, string>.
  • getSessionJwtFromCookieHeader(header) — returns the __session JWT or null.
  • verifySessionJwt(token, options) — standalone verifier if you prefer not to use the class.

How sessions work (short version)

KolayLogin uses a two-cookie design:

  • __client (httpOnly, long-lived) holds the refresh-capable session reference. It never leaves the browser → auth-API roundtrip.
  • __session (readable by JS, ~60s TTL) is a signed JWT your services verify locally. Short lifetime means a revoked session stops working within the skew window without you having to hit the auth API.

This package is the "verify __session locally" half. The browser SDK handles the refresh loop.

Error handling

jose-thrown errors bubble up with their original names (JWSSignatureVerificationFailed, JWTExpired, etc.). Production services should log the error class, not the token, and return a generic 401 to the client.

License

MIT