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

@saasifier/nextjs

v0.1.1

Published

Next.js middleware and route-handler bindings for SaaSify tenant resolution.

Readme

@saasifier/nextjs

Next.js middleware and route-handler bindings for SaaSify tenant resolution.

Installation

npm install @saasifier/nextjs

Overview

Next.js middleware and the route handler it targets can run as separate invocations (notably on the Edge runtime), so context bound with AsyncLocalStorage in middleware doesn't automatically reach the handler. @saasifier/nextjs bridges that gap: saasify.middleware() resolves the tenant/organization/user/role for an incoming request and forwards the result as request headers, and withSaaSContext() reads those headers back out on the other side and rebinds @saasifier/core's context store before invoking your handler. Together they make saas.context() work correctly across the middleware boundary.

Usage

// middleware.ts
import { saasify } from "@saasifier/nextjs";
import { saas } from "@/lib/saasify";
import { authAdapter } from "@/lib/auth";

export const middleware = saasify.middleware({
  saas,
  auth: authAdapter,
  strategy: "subdomain",
  baseDomain: "example.com"
});

export const config = {
  matcher: ["/((?!_next|favicon.ico).*)"]
};
// app/api/projects/route.ts
import { withSaaSContext } from "@saasifier/nextjs";
import { saas } from "@/lib/saasify";

export const GET = withSaaSContext(saas, async (request) => {
  const projects = await saas.entitlements.require("projects", () => listProjects());
  return Response.json(projects);
});

API Reference

  • saasify.middleware(options) (alias for createSaaSifyMiddleware) — builds the export const middleware = ... entry point. Options:

    • saas: SaaS — the @saasifier/core instance.
    • auth: AuthAdapter<NextRequest> — the app's auth adapter.
    • strategy: TenantResolutionStrategy — how to resolve the tenant from the request (e.g. subdomain, header, path).
    • baseDomain?: string — required for subdomain-based strategies.
    • tenantHeaderName?: string — override the header name used for header-based resolution.

    Resolves tenant context, forwards it as request headers (see SAASIFY_HEADERS), and returns NextResponse.next(). On failure, returns a JSON error response with the appropriate status: 401 (UnauthorizedError), 403 (ForbiddenError), 404 (TenantNotFoundError), or 400 (any other SaaSError).

  • withSaaSContext(saas, handler) — wraps an App Router route handler. Reads SAASIFY_HEADERS off the incoming request, binds them into saas.contextStore, and invokes handler(request, context) within that scope. Throws ConfigurationError if the headers are missing — meaning the route was reached without going through saasify.middleware()'s matcher.

  • SAASIFY_HEADERS — the header names used to carry resolved context across the middleware → handler boundary: x-saasify-tenant-id, x-saasify-organization-id, x-saasify-user-id, x-saasify-role.