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

@opble/mastra-auth0

v0.0.2

Published

Auth0 JWT middleware for Mastra servers.

Readme

@opble/mastra-auth0

Auth0 JWT middleware for Mastra servers. Protects your API routes by enforcing a valid Auth0 Bearer token on every request.

Installation

npm install @opble/mastra-auth0

Usage

Set the required environment variables:

AUTH0_DOMAIN=your-tenant.auth0.com
AUTH0_AUDIENCE=https://your-api-identifier

Then register the middleware on your Mastra server:

import { Mastra } from 'mastra';
import { createAuth0Middleware } from '@opble/mastra-auth0';

export const mastra = new Mastra({
  server: {
    middleware: [
      {
        path: '/api/*',
        handler: createAuth0Middleware() as any,
      },
    ],
  },
});

Note: The as any cast is required because @mastra/core vendors its own copy of Hono's types internally, causing a structural type mismatch at the assignment site. The middleware itself is fully type-safe — only the assignment into Mastra's config needs the cast.

That's it. Any request to /api/* without a valid Authorization: Bearer <token> header will receive a 401 response.

Environment variables

| Variable | Required | Default | Description | |----------|----------|---------|-------------| | AUTH0_DOMAIN | Yes | — | Your Auth0 tenant domain, e.g. your-tenant.auth0.com | | AUTH0_AUDIENCE | Yes | — | API Identifier registered in your Auth0 dashboard | | AUTH0_ENABLED | No | true | Set to false to disable auth (useful in local development) |

Options

All options are optional and override their corresponding environment variable:

createAuth0Middleware({
  domain: 'your-tenant.auth0.com',      // overrides AUTH0_DOMAIN
  audience: 'https://your-api',         // overrides AUTH0_AUDIENCE
  enabled: true,                        // overrides AUTH0_ENABLED
  contextKey: 'auth0User',              // key used to store JWT payload in Hono context
  getToken: (c) => c.req.header('x-token'),  // custom token extraction
  onSuccess: async (c, payload) => {    // called after successful verification
    c.set('MASTRA_RESOURCE_ID_KEY', payload.sub as string);
  },
  onError: async (c, err) => {          // custom error response
    return c.json({ error: 'Unauthorized' }, 401);
  },
})

License

UNLICENSED