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

@liam-public/browser-react-auth

v0.4.0

Published

React browser auth client, provider, JWT helpers, and authenticated fetch.

Downloads

184

Readme

@liam-public/browser-react-auth

Browser session store, React provider, JWT helpers, and an authenticated fetch. Framework-side half of a token auth flow — it holds and renews a session, and leaves how you obtain one (OIDC, password, passkey) to the caller's refresh callback.

import {
  createBrowserAuthClient,
  createWebStorageTokenStore,
  createAuthenticatedFetch,
  AuthProvider,
  useAuth,
} from '@liam-public/browser-react-auth'

const client = createBrowserAuthClient({
  storage: createWebStorageTokenStore(window.localStorage),
  refresh: async () => exchangeRefreshToken(),   // → session, or null when it is refused
})

<AuthProvider client={client}>
  <App />
</AuthProvider>

Exports

  • createBrowserAuthClient(options) — the session store: bootstrap, get/set/clear, refresh, subscribe, isAuthenticated().
  • createWebStorageTokenStore(storage) / createMemoryTokenStore()BrowserTokenStore implementations over localStorage/sessionStorage and a Map.
  • createAuthenticatedFetch(client, fetch?) — bearer injection with one refresh-and-retry on 401.
  • AuthProvider / useAuth() — React binding; useAuth() throws outside a provider.
  • decodeJwtPayload(token) / isJwtExpired(token, now?) — claim helpers. Decoding only, no signature verification: treat the payload as a hint for UI, never as an authorization decision.

Bearer only, no cookies

createAuthenticatedFetch sends credentials: 'omit' on both the first attempt and the retry, and that overrides whatever the caller passes. The bearer token is the only credential this client sends. A cookie riding along would be an ambient second credential the server might honour instead of the token — the confused-deputy shape bearer auth exists to avoid.

Concurrent 401s share a single refresh; the request is retried exactly once. Request bodies must be re-readable for that retry, so a stream body cannot be retried.

Storage keys

Keys default to a liam_browser_auth_ prefix. Two ways to change them:

createBrowserAuthClient({ …, keyPrefix: '' })                    // bare: access_token, refresh_token, user
createBrowserAuthClient({ …, keys: { refreshToken: 'my_rt' } })  // name keys outright; wins over keyPrefix

Use keys when another component shares the same storage and must agree on a name — an OIDC engine that renews from refresh_token, say. Two components writing one token under two names drift apart the moment either clears its copy alone, which leaves a usable credential behind after sign-out.

Refresh on load, not on a timer

bootstrap() restores the session from storage. If the stored access token has expired and a refresh token survives, it renews once before resolving — that is what stops a reload from bouncing a signed-in user to the login screen. Concurrent bootstrap() calls share one restore.

A refresh the server refuses (returns null) clears the session. A refresh that throws (offline) is swallowed and leaves the refresh token in place, so a later attempt can still succeed — a network blip should not destroy credentials.

There is no proactive background refresh: renewal happens on load and on a 401. AuthProvider awaits bootstrap() before clearing isLoading, so route guards never observe the expired window.