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

nest-better-auth

v1.1.0

Published

NestJS wrapper for Better Auth

Readme

Nest Better Auth

A small NestJS wrapper around Better Auth – the framework-agnostic authentication library for TypeScript.

It exposes Better Auth inside a standard Nest module (NestBetterAuthModule) and gives you:

  • NestBetterAuthService – access to the raw Better Auth instance
  • BetterAuthController – wires all /api/auth/** routes directly to Better Auth so every core feature & plugin works out-of-the-box
  • AuthGuard, @CurrentUser() & @CurrentSession() decorators – simple route protection

Installation

npm i nest-better-auth better-auth                 # peer dependency
# optional – pick your DB adapter / ORM
npm i drizzle-orm                                   # or prisma / kysely …

Quick start

import { Module } from '@nestjs/common';
import { NestBetterAuthModule } from 'nest-better-auth';
import Database from 'better-sqlite3';
import { twoFactor } from 'better-auth/plugins';

@Module({
  imports: [
    NestBetterAuthModule.forRoot({
      config: {
        database: new Database('./auth.db'),
        emailAndPassword: { enabled: true },
        plugins: [twoFactor()],
      },
    }),
  ],
})
export class AppModule {}

Every request to /api/auth/** is now handled by Better Auth. To protect a route:

@Get('profile')
@UseGuards(AuthGuard)
getProfile(@CurrentUser() user) {
  return user;
}

Using Better Auth plugins

Plugins simply go into the plugins array above. They work exactly as documented because the Nest layer never interferes with Better Auth’s internals.

If the plugin ships a DB schema run:

npx @better-auth/cli migrate           # or `generate` if you prefer SQL files

Add the matching client plugin on the frontend (React example):

import { createAuthClient } from 'better-auth/react';
import { twoFactorClient } from 'better-auth/client/plugins';

export const authClient = createAuthClient({
  plugins: [twoFactorClient({ twoFactorPage: '/2fa' })],
});

Protecting routes

To secure endpoints, import the helpers directly from this package:

import { Controller, Get, UseGuards } from '@nestjs/common';
import {
  AuthGuard,
  CurrentUser,
  CurrentSession,
} from 'nest-better-auth';

@Controller('profile')
export class ProfileController {
  // Guard verifies the user has a valid Better-Auth session
  @Get()
  @UseGuards(AuthGuard)
  getProfile(
    @CurrentUser() user: any,
    @CurrentSession() session: any,
  ) {
    return { user, session };
  }
}

AuthGuard calls auth.api.getSession() under the hood and populates request.user and request.session so they’re available to the @CurrentUser() and @CurrentSession() param decorators.

License

This project is licensed under the MIT license.

© 2025 Ezedin