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

@minion-stack/auth

v0.3.0

Published

Better Auth factory for the Minion platform — shared between minion_hub and minion_site.

Readme

@minion-stack/auth

Better Auth createAuth() factory shared between minion_hub and minion_site.

Overview

This package provides a single createAuth() factory function that creates a fully-configured Better Auth instance with consistent defaults across the Minion platform. It ensures JWT audience, cookie security, and account linking behave identically in both apps.

Always included by the factory:

  • JWT plugin (EdDSA keypair, 1h expiry, audience: 'openclaw-gateway', issuer: baseURL)
  • Email + password authentication
  • Account linking with Google as a trusted provider
  • Localhost dev origins (:5173, :5174, :4173)
  • useSecureCookies derived from baseURL (automatic in production)

Passed by callers (factory never calls these internally):

  • organization() — hub passes organization({ sendInvitationEmail }), site passes organization()
  • oidcProvider() — hub only

Install

This package is already included in the Minion meta-repo workspace. For external consumers:

npm install @minion-stack/auth [email protected]

Usage

Hub call-site (minion_hub/src/lib/auth/auth.ts)

import { createAuth, type AuthInstance } from '@minion-stack/auth';
import { organization, oidcProvider } from 'better-auth/plugins';
import { createAuthMiddleware } from 'better-auth/api';
import { getDb } from '$server/db/client';
import * as schema from '@minion-stack/db/schema';
import { env } from '$env/dynamic/private';
import { sendInvitationEmail } from '$server/services/email.service';
import { provisionPersonalAgent } from '$server/services/personal-agent.service';

let _auth: AuthInstance | null = null;

export function getAuth(): AuthInstance {
  if (!_auth) {
    const hubUrl = env.BETTER_AUTH_URL ?? 'http://localhost:5173';
    _auth = createAuth({
      db: getDb(),
      schema,
      secret: env.BETTER_AUTH_SECRET,
      baseURL: hubUrl,
      trustedOrigins: [
        ...(env.VERCEL_URL ? [`https://${env.VERCEL_URL}`] : []),
      ],
      google: env.GOOGLE_CLIENT_ID && env.GOOGLE_CLIENT_SECRET
        ? { clientId: env.GOOGLE_CLIENT_ID, clientSecret: env.GOOGLE_CLIENT_SECRET }
        : undefined,
      plugins: [
        organization({
          async sendInvitationEmail(data) {
            const baseUrl = env.BETTER_AUTH_URL ?? 'http://localhost:5173';
            await sendInvitationEmail({
              to: data.email,
              inviterName: data.inviter.user.name ?? data.inviter.user.email,
              organizationName: data.organization.name,
              role: data.role ?? 'member',
              inviteUrl: `${baseUrl}/invite/accept?id=${data.id}`,
            });
          },
        }),
        oidcProvider({ loginPage: '/login' }),
      ],
      hooks: {
        after: createAuthMiddleware(async (ctx) => {
          if (ctx.path.startsWith('/sign-up')) {
            const newSession = ctx.context.newSession;
            if (newSession) {
              try {
                await provisionPersonalAgent(
                  { db: getDb(), tenantId: 'default' },
                  { userId: newSession.user.id, email: newSession.user.email, serverId: '' }
                );
              } catch (err) {
                console.error('[personal-agent] Failed to provision on signup:', err);
              }
            }
          }
        }),
      },
    });
  }
  return _auth;
}

Site call-site (minion_site/src/lib/auth/auth.ts)

import { createAuth, type AuthInstance } from '@minion-stack/auth';
import { organization } from 'better-auth/plugins';
import { getDb } from '$server/db/client';
import * as schema from '@minion-stack/db/schema';
import { env } from '$env/dynamic/private';

let _auth: AuthInstance | null = null;

export function getAuth(): AuthInstance {
  if (!_auth) {
    _auth = createAuth({
      db: getDb(),
      schema,
      secret: env.BETTER_AUTH_SECRET,
      baseURL: env.BETTER_AUTH_URL ?? 'http://localhost:5173',
      trustedOrigins: [
        ...(env.VERCEL_URL ? [`https://${env.VERCEL_URL}`] : []),
      ],
      google: env.GOOGLE_CLIENT_ID && env.GOOGLE_CLIENT_SECRET
        ? { clientId: env.GOOGLE_CLIENT_ID, clientSecret: env.GOOGLE_CLIENT_SECRET }
        : undefined,
      plugins: [organization()],
    });
  }
  return _auth;
}

Environment Contract

| Variable | Required | Description | |----------|----------|-------------| | BETTER_AUTH_SECRET | Yes | Auth signing secret. Must be identical between hub and site for session continuity. | | BETTER_AUTH_URL | Yes | Full URL of the auth app (e.g. https://hub.minion.pe). Used as JWT issuer. | | GOOGLE_CLIENT_ID | No | Google OAuth client ID. Omit to disable Google sign-in. | | GOOGLE_CLIENT_SECRET | No | Google OAuth client secret. Omit to disable Google sign-in. |

Both BETTER_AUTH_SECRET and BETTER_AUTH_URL are managed via Infisical minion-hub project — both apps pull from the same Infisical project to guarantee secret parity.

Version Pinning

Stay on [email protected]. Do NOT upgrade without a coordinated hub + site deploy:

See Phase 6 research notes (.planning/phases/06-auth-extraction/06-RESEARCH.md, Pitfall 5) for full context.

The peer dependency is pinned to the exact version "better-auth": "1.4.19" to prevent accidental silent upgrades via npm update.