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

@dunx/auth

v3.10.2

Published

Better Auth for dunx: its handler mounted on Bun.serve, a session guard reading @Public() and @Roles(), the caller in async context, and Bun.password hashing

Readme

@dunx/auth

Better Auth for dunx.

This package connects better-auth to dunx. It gives you a module that builds the better-auth instance from your ConfigService, five routes that mount its handler, a guard that respects @dunx/http's @Public() and @Roles(), and two adapters that run better-auth on Bun's own APIs.

better-auth handles authentication itself; this package does not reimplement it.

There is no dunx sign-in flow, no dunx session table and no dunx OAuth. Each is a better-auth feature reached through AuthModule.forRoot's options, which are better-auth's BetterAuthOptions.

Install

bun add @dunx/auth better-auth

better-auth is a required peer: this package imports betterAuth as a value and cannot load without it. drizzle-orm is an optional peer, needed only by @dunx/auth/drizzle - its own subpath so a Prisma, Kysely or MongoDB app never loads it.

Usage

import { AuthModule, SessionGuard } from '@dunx/auth';
import { drizzleDatabase } from '@dunx/auth/drizzle';
import { Module } from '@dunx/core';
import { HttpFactory } from '@dunx/http';
import { DbConnection } from '@dunx/infra/db';

@Module({
  imports: [
    AuthModule.forRootAsync({
      imports: [DatabaseModule],
      inject: [AppConfigService, DbConnection],
      useFactory: (config: AppConfigService, connection: DbConnection) => ({
        secret: config.get('auth').secret,
        basePath: '/api/auth',
        database: drizzleDatabase(connection),
        emailAndPassword: { enabled: true },
      }),
    }),
  ],
})
export class AuthFeatureModule {}

// Globally, and opt routes out with @Public():
HttpFactory.create(AppModule, { middleware: [SessionGuard] });

What is here

The Authentication guide is canonical.

| Export | What it does | | --------------------- | ----------------------------------------------------------------- | | AuthModule | Builds the instance, mounts the handler, binds the guard | | Auth | The better-auth instance, injectable | | SessionGuard | Authenticates, honours @Public() and @Roles() | | AuthContext | The authenticated caller, anywhere in the request | | betterAuthDocument | better-auth's own paths merged into the OpenAPI document | | bunPassword | Bun.password native bcrypt, applied by default | | @dunx/auth/drizzle | better-auth over the connection the app already opened | | redisStorage | secondaryStorage over Bun.RedisClient |

Notes

  • dunx does not ship a schema for better-auth's tables, because better-auth owns them and they change with its plugins. Generate them with bunx @better-auth/cli generate, and export them under the singular model names the adapter looks up.
  • Under setGlobalPrefix, basePath is what better-auth matches. mountAt is where the route is mounted. Omitting mountAt with a non-default basePath is a boot error.
  • AuthContext is a second AsyncLocalStorage store rather than a key in RequestContext. Everything in that store is serialized into every log line the request writes.

License

MIT