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

@slashclick/auth

v0.3.0

Published

Shared auth UI components, hooks, schemas, and better-auth client factory

Readme

@slashclick/auth

This package provides shared auth UI (SigninFormCard) and a better-auth client factory. It handles the UI and client-side flow. Each consuming app is responsible for its own better-auth server configuration, database connection, and — critically — rate limiting.


Required: Rate Limiting

Without rate limiting, auth endpoints are open to brute-force attacks.

This package does not bundle rate limiting because it belongs on the server in each consuming app. You must implement it before going to production.

Option A: better-auth Rate Limit Plugin (Recommended)

better-auth ships a built-in rate limit plugin. Add it to your server config:

// apps/your-app/auth.ts
import { betterAuth } from 'better-auth'
import { rateLimit } from 'better-auth/plugins'

export const auth = betterAuth({
  database: {
    /* your db config */
  },
  plugins: [
    rateLimit({
      window: 60,
      max: 5,
      customRules: {
        '/sign-in/email': { window: 60, max: 5 },
        '/sign-up/email': { window: 60, max: 3 },
        '/forget-password': { window: 3600, max: 3 },
        '/resend-verification-email': { window: 3600, max: 3 },
      },
    }),
  ],
})

Option B: Server Action Wrapper (Manual)

If you use Next.js Server Actions for auth, apply rate limiting before calling auth.api.signInEmail. Write a small rateLimit helper for your app (e.g. backed by Redis or an in-memory token bucket) and wrap each action with it:

// apps/your-app/actions/signIn.ts
'use server'
import { headers } from 'next/headers'
import { auth } from '../auth'
import { rateLimit, AuthRateLimits } from '../lib/rate-limit'

export async function signInAction(values: {
  emailOrUsername: string
  password: string
}) {
  const headersList = await headers()
  const req = new Request('http://localhost', { headers: headersList })

  const limited = await rateLimit(req, AuthRateLimits.signIn)
  if (limited) return { error: 'Too many attempts. Please try again later.' }

  // ... rest of sign-in logic
}

The AuthRateLimits config should be:

export const AuthRateLimits = {
  signIn: {
    tokensPerInterval: 5,
    interval: 'minute' as const,
    failClosed: true,
  },
  signUp: {
    tokensPerInterval: 3,
    interval: 'minute' as const,
    failClosed: true,
  },
  resend: { tokensPerInterval: 3, interval: 'hour' as const, failClosed: true },
  reset: { tokensPerInterval: 3, interval: 'hour' as const, failClosed: true },
}

failClosed: true is critical — if the rate limiter errors, it returns 503 instead of letting the request through.


Pre-Production Checklist

  • [ ] Rate limiting on sign-in (max 5/min per IP, fail closed)
  • [ ] Rate limiting on sign-up (max 3/min per IP, fail closed)
  • [ ] Rate limiting on password reset (max 3/hr per IP, fail closed)
  • [ ] Rate limiting on resend verification (max 3/hr per IP, fail closed)
  • [ ] emailVerificationRequired: true in better-auth server config
  • [ ] NEXT_PUBLIC_APP_URL env var set correctly in production
  • [ ] No hardcoded secrets — all credentials via environment variables
  • [ ] .env in .gitignore

Usage in a New App

1. Install

npm install @slashclick/auth

2. Create the auth client

// lib/auth-client.ts
import { createSharedAuthClient } from '@slashclick/auth'

export const authClient = createSharedAuthClient({
  baseURL: process.env.NEXT_PUBLIC_APP_URL ?? 'http://localhost:3000',
})

export const { signIn, signUp, signOut, useSession } = authClient

3a. Use with a Server Action (supports username resolution)

// app/(auth)/signin/page.tsx
import { SigninFormCard } from '@slashclick/auth'
import { signInAction } from '../../actions/signIn'    // your rate-limited action
import { resendAction } from '../../actions/resend'

export default function SigninPage() {
  const handleSignOut = async () => {
    'use server'
    // call your auth.signOut()
  }
  return (
    <SigninFormCard
      providers={[]}
      credentials
      credentialsSignin={signInAction}
      resendVerificationEmail={resendAction}
      signOut={handleSignOut}
    />
  )
}

3b. Use with the default hook (email only, no username resolution)

// app/(auth)/signin/SigninWrapper.tsx
'use client'
import { useSignIn, SigninFormCard } from '@slashclick/auth'
import { authClient } from '../../lib/auth-client'

export function SigninWrapper() {
  const { credentialsSignin } = useSignIn(authClient)

  return (
    <SigninFormCard
      providers={[]}
      credentials
      credentialsSignin={credentialsSignin}
      signOut={async () => { /* call authClient.signOut() */ }}
    />
  )
}

What Lives Where

| Concern | Lives in | Why | | -------------------------------- | ------------------ | ------------------------ | | UI components (SigninFormCard) | @slashclick/auth | Shared | | Validation schemas | @slashclick/auth | Shared | | useSignIn hook | @slashclick/auth | Shared (email only) | | better-auth server config | Each consuming app | Needs DB, email, secrets | | Rate limiting | Each consuming app | Needs server context | | Username→email resolution | Each consuming app | App-specific DB query | | Email service (Resend etc.) | Each consuming app | App-specific credentials |


Notes

  • SigninFormCard uses next/navigation (useSearchParams, useRouter) and targets Next.js apps. If you need a non-Next.js consumer, these can be abstracted behind props.
  • The credentialsSignin prop accepts any function matching CredentialsSigninFn — pass a Server Action for username support, or use useSignIn(authClient) for email-only apps.
  • Register, reset-password, and verify screens follow the same pattern and will be added to this package in a follow-up.