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

@authprovider/auth-client

v0.1.2

Published

Configurable auth client with Axios refresh, proactive token rotation, and optional React bindings.

Downloads

284

Readme

@authprovider/auth-client

Configurable authentication client with:

  • Axios request auth headers
  • Automatic token refresh with axios-auth-refresh
  • Proactive refresh before access token expiry
  • Cross-tab synchronization via broadcast-channel
  • Optional React bindings (AuthProvider, useAuth)

This package is built for backend contracts that expose:

  • POST /auth/login
  • POST /auth/refresh
  • POST /auth/logout
  • GET /auth/me

and return token payloads containing access_token, optional refresh_token, and expires_at.

Install

npm install @authprovider/auth-client

Core Usage (Framework-agnostic)

import { createAuthClient } from '@authprovider/auth-client'

const auth = createAuthClient({
  baseURL: 'http://localhost:5002',
  clientType: 'mobile',
})

const http = auth.getHttpClient()

await auth.bootstrap()
await auth.login({ loginName: 'demo', password: 'secret' })

const user = await auth.me()
console.log(user)

You can use auth.getHttpClient() as your app's API client. It is already configured with:

  • auth request headers
  • automatic 401 refresh handling
  • refresh queueing for concurrent requests

React Usage

import { createAuthClient } from '@authprovider/auth-client'
import { AuthProvider, useAuth } from '@authprovider/auth-client/react'

const authClient = createAuthClient({
  baseURL: import.meta.env.VITE_API_BASE_URL,
  clientType: 'mobile',
})

function LoginButton() {
  const { login, isAuthenticated } = useAuth()

  if (isAuthenticated) {
    return null
  }

  return (
    <button onClick={() => void login({ loginName: 'demo', password: 'secret' })}>
      Login
    </button>
  )
}

function Root() {
  return (
    <AuthProvider client={authClient}>
      <LoginButton />
    </AuthProvider>
  )
}

AuthProvider bootstraps automatically by default. Set autoBootstrap={false} if you want full manual control.

Configuration

import { createAuthClient, localStorageStorage } from '@authprovider/auth-client'

const auth = createAuthClient({
  baseURL: 'https://api.example.com',
  clientType: 'web',

  endpoints: {
    login: '/auth/login',
    refresh: '/auth/refresh',
    logout: '/auth/logout',
    me: '/auth/me',
  },

  headers: {
    clientTypeHeader: 'X-Client-Type',
  },

  refresh: {
    strategy: 'cookie',
    withCredentials: true,
    retryOn401: true,
  },

  proactiveRefresh: {
    enabled: true,
    leadTimeMs: 60_000,
    jitterMs: 10_000,
    minIntervalMs: 5_000,
  },

  multiTab: {
    enabled: true,
    channelName: 'auth_channel',
    lockKey: 'auth.refresh.lock',
    lockTtlMs: 10_000,
    waitTimeoutMs: 10_000,
  },

  storage: {
    adapter: localStorageStorage('myapp.auth'),
  },

  hooks: {
    onAuthFailure: (error) => {
      console.error('Auth failed', error)
    },
    onTokenUpdate: (tokenInfo) => {
      console.log('Token update', tokenInfo.expiresAt)
    },
  },
})

Storage Adapters

Built-in helpers:

  • memoryStorage() (default)
  • localStorageStorage(prefix?)

You can provide your own AuthStorageAdapter if needed.

API Surface

From @authprovider/auth-client:

  • createAuthClient(config)
  • memoryStorage()
  • localStorageStorage(prefix?)

Client methods:

  • bootstrap()
  • login({ loginName, password })
  • logout()
  • refreshNow()
  • me()
  • getHttpClient()
  • getRefreshHttpClient()
  • getState()
  • subscribe(listener)
  • destroy()

From @authprovider/auth-client/react:

  • AuthProvider
  • useAuth

Security Notes

  • For browser apps, prefer clientType: 'web' with cookie refresh strategy when your backend supports HttpOnly refresh cookies.
  • Access tokens are automatically refreshed before expiry when proactive refresh is enabled.
  • 401-based refresh fallback remains active for race conditions and browser sleep/wake scenarios.

Development

npm run lint
npm run typecheck
npm run build
npm run audit