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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@getlumen/better-auth

v0.1.5

Published

Better Auth plugin for Lumen

Downloads

80

Readme

Better Auth Lumen Plugin

A Better Auth plugin that automatically creates free subscriptions when users sign up or log in via email or social providers.

Installation

npm install # This is a local package in the monorepo

Usage

Basic Usage

import { betterAuth } from "better-auth";
import { LumenPlugin } from "@getlumen/better-auth";

export const auth = betterAuth({
  // ... your other Better Auth configuration

  plugins: [
    LumenPlugin({
      apiUrl: process.env.API_URL || "https://api.getlumen.dev",
      apiKey: process.env.LUMEN_API_KEY!,
      enabled: true,
      prodOnly: true, // Only run in production/staging
    }),
  ],
});

Advanced Usage with Callbacks

import { betterAuth } from "better-auth";
import { LumenPlugin } from "@getlumen/better-auth";

export const auth = betterAuth({
  // ... your other Better Auth configuration

  plugins: [
    LumenPlugin({
      apiUrl: process.env.API_URL || "https://api.getlumen.dev",
      apiKey: process.env.LUMEN_API_KEY!,
      enabled: true,
      prodOnly: process.env.NODE_ENV !== "development",
      onSuccess: (user, subscription) => {
        console.log(
          `Free subscription created for ${user.email}:`,
          subscription
        );
        // Optional: Send notification, update analytics, etc.
      },
      onError: (user, error) => {
        console.error(
          `Failed to create free subscription for ${user.email}:`,
          error
        );
        // Optional: Send error notification, log to monitoring service, etc.
      },
      logger: (message, ...args) => {
        console.log(`[FreeSubscription] ${message}`, ...args);
      },
    }),
  ],
});

Integration with Other Plugins

If you have other plugins, you can combine them:

import { betterAuth } from "better-auth";
import { LumenPlugin } from "@getlumen/better-auth";
import { someOtherPlugin } from "some-other-plugin";

export const auth = betterAuth({
  // ... your other Better Auth configuration

  plugins: [
    someOtherPlugin(),
    LumenPlugin({
      apiUrl: process.env.API_URL || "https://api.getlumen.dev",
      apiKey: process.env.LUMEN_API_KEY!,
      enabled: true,
      prodOnly: true,
    }),
  ],
});

Configuration Options

| Option | Type | Default | Description | | ----------- | ---------- | -------------------------- | ------------------------------------------------------------------ | | apiUrl | string | https://api.getlumen.dev | The base URL of your API service | | apiKey | string | Required | API key for authenticating with the subscription service | | enabled | boolean | true | Whether the plugin is enabled | | prodOnly | boolean | false | Whether to only run in production/staging environments | | onSuccess | function | Optional | Callback function called when subscription is created successfully | | onError | function | Optional | Callback function called when subscription creation fails | | logger | function | console.log | Custom logger function for debugging |

How It Works

  1. The plugin hooks into the Better Auth after hook with a matcher
  2. It checks if the current request is a sign-in endpoint (email login or social callback)
  3. If a new session is created, it automatically calls the /v1/subscriptions/create-free-subscription endpoint
  4. The subscription is created with the user's email, name, and ID
  5. Success/error callbacks are triggered accordingly

Environment Variables

Make sure to set these environment variables:

API_URL=https://api.getlumen.dev  # Your API base URL (optional, defaults to production)
LUMEN_API_KEY=your-api-key-here  # Your Lumen API key (required)

Error Handling

The plugin includes comprehensive error handling:

  • Missing API key will skip subscription creation
  • Network errors are caught and logged
  • API errors are parsed and passed to the error callback
  • Errors don't block user authentication (fail gracefully)

Development vs Production

When prodOnly is set to true, the plugin will skip execution in development mode. This is useful for preventing test subscriptions from being created during development.

Debugging

Enable debug logging by providing a custom logger:

logger: (message, ...args) => {
  if (process.env.NODE_ENV === "development") {
    console.log(`[DEBUG] ${message}`, ...args);
  }
};

Plugin ID

The plugin registers with the ID lumen-payments in the Better Auth system.