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

@wocha/express

v0.1.0

Published

Express.js middleware for Wocha authentication and authorisation

Readme

@wocha/express

Express.js middleware for Wocha authentication and authorisation. Validates JWT access tokens against your Wocha issuer JWKS, attaches session context to req.wocha, checks SpiceDB permissions, and verifies webhook signatures.

Install

npm install @wocha/express express
# or: pnpm add / yarn add

Peer dependency: express ^4.18 or ^5.0.

Quick start

Environment variables

WOCHA_ISSUER_URL=https://my-tenant.auth.wocha.ai
WOCHA_CLIENT_ID=your-client-id
WOCHA_CLIENT_SECRET=your-client-secret
# Optional:
WOCHA_AUDIENCE=your-api-audience
WOCHA_API_URL=https://my-tenant.api.wocha.ai
WOCHA_COOKIE_SECRET=optional-separate-cookie-secret

Protect API routes

import express from "express";
import { wochaAuth } from "@wocha/express";

const app = express();
app.use(express.json());

const auth = wochaAuth({
  issuerUrl: process.env.WOCHA_ISSUER_URL!,
  clientId: process.env.WOCHA_CLIENT_ID!,
  clientSecret: process.env.WOCHA_CLIENT_SECRET!,
  audience: process.env.WOCHA_AUDIENCE,
});

// Attach req.wocha on every request (user may be null)
app.use(auth.middleware());

app.get("/health", (_req, res) => {
  res.json({ status: "ok" });
});

app.get("/api/profile", auth.requireAuth(), (req, res) => {
  res.json(req.wocha.user);
});

app.delete("/api/posts/:id", auth.requirePermission("post", "delete"), (req, res) => {
  res.status(204).send();
});

app.get("/api/org-dashboard", auth.requireOrg(), (req, res) => {
  res.json({ org: req.wocha.org });
});

Webhook receiver

Register the webhook route before express.json() and use a raw body parser:

import express from "express";
import { verifyWebhook } from "@wocha/express";

const app = express();

app.post(
  "/webhooks/wocha",
  express.raw({ type: "application/json" }),
  verifyWebhook(process.env.WOCHA_WEBHOOK_SECRET!),
  (req, res) => {
    const event = req.wochaEvent;
    console.log(event?.event_type, event?.data);
    res.json({ received: true });
  },
);

app.use(express.json());

req.wocha context

After auth.middleware() runs, each request exposes:

| Field | Type | Description | |-------|------|-------------| | user | GreetUser \| null | Authenticated user claims | | session | GreetSession \| null | Access token and expiry | | org | GreetOrganisation \| null | Active organisation | | permissions | string[] | Permissions embedded in the access token | | featureFlags | Record<string, unknown> | Feature flags from the access token | | isAuthenticated | boolean | Whether a valid session was resolved |

Session resolution

The middleware resolves authentication from:

  1. Authorization: Bearer header — validates the JWT signature against JWKS (via jose)
  2. Encrypted session cookie — compatible with @wocha/remix / @wocha/nextjs BFF cookies; refreshes tokens automatically when near expiry

API reference

wochaAuth(config)

Returns an auth instance with:

  • middleware() — populate req.wocha (non-blocking)
  • requireAuth() — 401 when unauthenticated
  • requirePermission(resourceType, permission, options?) — SpiceDB check via Customer API; 403 when denied
  • requireOrg(orgId?) — ensure org membership; 403 when denied

verifyWebhook(secret, options?)

Express middleware that verifies X-Wocha-Signature and sets req.wochaEvent.

Token format

Wocha issues JWT access tokens signed via JWKS. This middleware validates them locally — no callback to Wocha is needed. For advanced patterns like tiered validation (local JWT for reads, introspection for mutations), see the Resource server guide.

Related packages

License

Apache-2.0