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

@airdraft/plugin-auth

v0.1.10

Published

Airdraft auth plugin — GitHub OAuth, email/password providers

Readme

@airdraft/plugin-auth

Authentication plugin for Airdraft. Adds email/password login, OAuth (GitHub, Google), team invitations, and role-based access control to your CMS.

Installation

npm install @airdraft/plugin-auth

Usage

withAutoAuth (recommended)

Auto-selects the provider based on environment variables. Uses CredentialsProvider when AIRDRAFT_JWT_SECRET is set, falling back to a read-only API-key-only mode otherwise.

import { withAutoAuth } from '@airdraft/plugin-auth'

const auth = await withAutoAuth()

export const airdraft = defineConfig({
  adapter,
  collections,
  plugins: [auth],
})

withAuth (explicit)

import { withAuth, CredentialsProvider } from '@airdraft/plugin-auth'

const auth = withAuth({
  provider: CredentialsProvider({
    userStore,
    secret: process.env.AIRDRAFT_JWT_SECRET!,
  }),
  publicPaths: ['/api/cms/posts'],  // optional — bypass auth on specific routes
})

Providers

CredentialsProvider

Email/password login stored in .airdraft/users.json.

import { CredentialsProvider, UserStore } from '@airdraft/plugin-auth'

const userStore = new UserStore()  // reads .airdraft/users.json

CredentialsProvider({
  userStore,
  secret: process.env.AIRDRAFT_JWT_SECRET!,
  roles: { '[email protected]': 'admin' },  // optional per-email role overrides
  basePath: '/api/cms',
})

GitHubOAuthProvider

GitHub OAuth login. Supports allowlists by user login or organisation membership.

import { GitHubOAuthProvider } from '@airdraft/plugin-auth'

GitHubOAuthProvider({
  clientId: process.env.GITHUB_CLIENT_ID!,
  clientSecret: process.env.GITHUB_CLIENT_SECRET!,
  secret: process.env.AIRDRAFT_JWT_SECRET!,
  allowedOrgs: ['my-org'],         // optional
  allowedUsers: ['my-user'],       // optional
  defaultRole: 'editor',           // default: 'editor'
})

GoogleOAuthProvider

Google OAuth login. Supports allowlists by email address or domain.

import { GoogleOAuthProvider } from '@airdraft/plugin-auth'

GoogleOAuthProvider({
  clientId: process.env.GOOGLE_CLIENT_ID!,
  clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
  secret: process.env.AIRDRAFT_JWT_SECRET!,
  allowedDomains: ['mycompany.com'],
  defaultRole: 'editor',
})

UserStore

Manages users and invitations stored in .airdraft/users.json.

import { UserStore } from '@airdraft/plugin-auth'

const userStore = new UserStore()

// Add a user
await userStore.addUser({ email: '[email protected]', role: 'admin', passwordHash: '...' })

// Create an invite
const invite = await userStore.createInvite({ email: '[email protected]', role: 'editor' })

// Accept an invite
await userStore.acceptInvite(invite.token, { password: 'secure123' })

The JSON file path can be overridden:

const userStore = new UserStore({ path: './.airdraft/users.json' })

getRequestUser(req)

Extracts and verifies the current user from a request (checks cookie, Bearer token, and X-API-Key header). Returns AuthUser | null.

import { getRequestUser } from '@airdraft/plugin-auth'

const user = getRequestUser(request)

refreshTokenBlocklist

In-memory blocklist for invalidated refresh tokens. Automatically cleared of expired entries on each check.

import { refreshTokenBlocklist } from '@airdraft/plugin-auth'

refreshTokenBlocklist.add(token)
refreshTokenBlocklist.has(token)  // returns false after TTL expires

Exports

| Export | Description | |---|---| | withAuth(options) | Creates the auth plugin with an explicit provider | | withAutoAuth(options?) | Auto-configured auth plugin | | CredentialsProvider(options) | Email/password provider | | GitHubOAuthProvider(options) | GitHub OAuth provider | | GoogleOAuthProvider(options) | Google OAuth provider | | UserStore | User and invite store backed by .airdraft/users.json | | getRequestUser(req) | Extract AuthUser from a request | | refreshTokenBlocklist | In-memory refresh token blocklist | | ROLE_PERMISSIONS | Record<Role, RolePermissions> constant | | can(user) | Returns RolePermissions for a user |

Changelog

See CHANGELOG.md.