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

ngx-better-auth

v0.10.2

Published

An **Angular 20+ wrapper for [Better Auth](https://github.com/better-auth/better-auth)**. Provides reactive session handling with **signals**, clean **DI provider setup** with **observables**, and modern **guards**.

Readme

ngx-better-auth

An Angular 20+ wrapper for Better Auth. Provides reactive session handling with signals, clean DI provider setup with observables, and modern guards.

npm npm bundle size license downloads

angular better-auth


🚀 Compatibility

| ngx-better-auth | Angular | Better Auth | |-----------------|---------|-------------| | latest | >=20 | >=1.3.7 |


📦 Installation

npm install ngx-better-auth better-auth

⚙️ Setup Provider

First, configure your Better Auth client in your application:

// app.config.ts
import { ApplicationConfig } from '@angular/core'
import { provideBetterAuth } from 'ngx-better-auth'
import { environment } from './environments/environment'
import { adminClient, twoFactorClient, usernameClient } from 'better-auth/client/plugins'

export const appConfig: ApplicationConfig = {
  providers: [
    provideBetterAuth({
      baseURL: environment.apiUrl, // it works also with proxy config
      basePath: '/auth',   // optional, default is '/api/auth'
        
      // Example with plugins
      plugins: [
        usernameClient(),
        twoFactorClient({
          onTwoFactorRedirect() {
              window.location.href = '/two-factor-auth'
          },
        }),
        adminClient({
          ac: accessControl,
          roles: {
            admin,
            moderator,
            user,
          },
        }),
      ],
    })
  ]
}

🧩 Different services

You can inject different services depending on your needs.
AuthService provides the core Better Auth client methods (signIn, signOut, signUp, e.g.).
The full list of methods is available at the end of this README.

🔌 Plugin compatibility

Authentication

  • ✅ Two Factor ➡️ TwoFactorService
  • ✅ Username ➡️ UsernameService
  • ❌ Anonymous
  • ❌ Phone Number
  • ✅ Magic Link ➡️ MagicLinkService
  • ✅ Email OTP ➡️ EmailOtpService
  • ✅ Passkey ➡️ PasskeyService
  • ✅ Generic OAuth ➡️ GenericOauthService
  • ✅ One Tap ➡️ OneTapService
  • ❌ Sign In With Ethereum

Authorization

  • ✅ Admin ➡️ AdminService
  • ❌ API Key
  • ❌ MCP
  • ✅ Organization ➡️ OrganizationService

Enterprise

  • ❌ OIDC Provider
  • ❌ SSO

Utility

  • ❌ Bearer
  • ❌ Device Authorization
  • ❌ Captcha
  • ❌ Last Login Method
  • ❌ Multi Session
  • ❌ One Time Token
  • ❌ JWT

🔄 Real-time Session

AuthService keeps the session in sync automatically

  • session → a signal with the current session or null
  • isLoggedIn → a computed boolean

Demonstration of usage in a component

import { AuthService } from "ngx-better-auth"
import { inject } from "@angular/core"

@Component({
    // ...
})
export class MyComponent {
    private readonly authService = inject(AuthService)

    get isLoggedIn() {
        return this.authService.isLoggedIn()
    }

    get userName() {
        return this.authService.session()?.user.name
    }
}

🛡️ Guards

This library ships with guards to quickly set up route protection.

Helpers

  • redirectUnauthorizedTo(['/login']) → redirect if not logged in
  • redirectLoggedInTo(['/']) → redirect if already logged in
  • hasRole(['admin'], ['/unauthorized']) → restrict access by role and redirect if not authorized

Usage in routes

import { Routes } from '@angular/router'
import { canActivate, redirectLoggedInTo, redirectUnauthorizedTo, hasRole } from 'ngx-better-auth'

export const routes: Routes = [
  {
    path: '',
    component: SomeComponent,
    ...canActivate(redirectUnauthorizedTo(['/login']))
  },
  {
    path: 'admin',
    component: AdminComponent,
    ...canActivate(hasRole(['admin'], ['/unauthorized']))
  },
  {
    path: 'login',
    component: LoginComponent,
    ...canActivate(redirectLoggedInTo(['/']))
  }
]

✅ Validators

The username plugin provides validators that work seamlessly with both reactive and template-driven forms.

import { FormControl } from '@angular/forms'
import { inject } from '@angular/core'
import { UsernameAvailableValidator } from 'ngx-better-auth'

const usernameService = inject(UsernameService)
const initialUsername = 'thomas-orgeval'

const usernameControl = new FormControl('', {
    asyncValidators: [usernameAvailableValidator(usernameService, initialUsername)],
    updateOn: 'change'
})