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

@take-out/better-auth-utils

v0.0.32

Published

Better auth utilities and client for React/React Native applications

Readme

@take-out/better-auth-utils

Better Auth utilities and helpers for React/React Native applications.

Features

  • JWT support for Zero, web and React Native
  • Session persistence in local storage
  • Token validation and refresh
  • State management with emitters
  • Automatic retry on authentication errors
  • TypeScript support with full type safety

Installation

bun add @take-out/better-auth-utils

Usage

Basic Setup

import { createBetterAuthClient } from '@take-out/better-auth-utils'
import { adminClient, magicLinkClient } from 'better-auth/client/plugins'

const authClient = createBetterAuthClient({
  baseURL: 'https://your-app.com',
  plugins: [adminClient(), magicLinkClient()],
  // Optional callbacks
  onAuthStateChange: (state) => {
    console.info('Auth state changed:', state)
  },
  onAuthError: (error) => {
    console.error('Auth error:', error)
  },
})

// Export for use throughout your app
export const {
  authClient,
  useAuth,
  getAuth,
  setAuthClientToken,
  clearAuthClientToken,
} = authClient

Using in React Components

import { useAuth } from './auth'

function UserProfile() {
  const { user, state } = useAuth()

  if (state === 'loading') return <div>Loading...</div>
  if (state === 'logged-out') return <div>Please log in</div>

  return <div>Welcome, {user?.name}!</div>
}

Custom User Types

import type { User } from '@take-out/better-auth-utils'

interface MyUser extends User {
  role?: 'admin' | 'user'
  preferences?: {
    theme: 'light' | 'dark'
  }
}

const authClient = createBetterAuthClient<any, MyUser>({
  baseURL: 'https://your-app.com',
})

Configuration Options

  • baseURL - The base URL for your auth server
  • plugins - Array of better-auth plugins
  • onAuthStateChange - Callback when auth state changes
  • onAuthError - Callback for handling auth errors
  • storagePrefix - Prefix for local storage keys (default: 'auth')
  • retryDelay - Delay in ms after auth errors (default: 4000)
  • tokenValidationEndpoint - Custom token validation endpoint (default: '/api/auth/validateToken')

API

createBetterAuthClient(options)

Creates a new authentication client with the provided options.

useAuth()

React hook that returns the current authentication state.

getAuth()

Gets the current authentication state (non-reactive).

setAuthClientToken({ token, session })

Sets the authentication token and session.

clearAuthClientToken()

Clears the stored authentication token.

clearState()

Clears all authentication state and storage.

Development

# Install dependencies
bun install

# Build the package
bun run build

# Run in watch mode
bun run watch

# Lint the code
bun run lint:fix

License

MIT