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

@kiavi/kiavi-browser

v0.3.1

Published

Kiavi browser authentication client

Readme

@kiavi/kiavi-browser

Browser client for apps that sign users in through a Kiavi-hosted auth server.

Install

pnpm add @kiavi/kiavi-browser

Usage

import { KiaviClient } from '@kiavi/kiavi-browser'

const auth = new KiaviClient('https://auth.your-domain.com')

// Guard a route — if there's no session, the user is redirected to login.
const session = await auth.authenticate()

// Attach the token to API calls.
const token = await auth.getAccessToken()
fetch('/api/things', { headers: { Authorization: `Bearer ${token}` } })

// Sign out.
await auth.signOut()

That's the whole thing. authenticate() at the top of your app and getAccessToken() on every API call is enough for most apps.

Options

new KiaviClient('https://auth.your-domain.com', {
  locale: 'en', // adds ?lang=en to hosted pages
  debug: true, // structured console logs; pass a function to route them elsewhere
})

Reference

Methods

  • authenticate(options?) — ensures a session exists. Resolves with a KiaviSession if one is already live, silently refreshable, or recovered from the auth callback. Otherwise redirects to the hosted login page and never resolves.
  • getAccessToken() — returns a valid JWT, refreshing silently if the current one is near or past expiry. Throws KiaviSessionExpiredError if a new token can't be obtained.
  • getSession() — non-redirecting read of the current session. Returns KiaviSession | null. Safe to call on the server.
  • signOut(options?) — clears local state, revokes server-side, and redirects to the hosted signout page. Pass { redirect: false } to skip navigation.
  • onAuthStateChange(listener) — subscribe to session changes. Returns an unsubscribe function.
  • getAuthPolicy() — returns 'passkey_required' or 'passkey_preferred', for UI that adapts to the configured policy.
  • resendVerificationEmail({ email, callbackURL? }) — unauthenticated. Asks the auth server to send another verification email. Throws KiaviAuthError on failure (code includes 'rate_limited', in which case retryAfterSeconds is populated).
  • changeEmail({ newEmail, callbackURL? }) — requires an active session. Asks the auth server to change the signed-in user's email. If the current email is verified, a confirmation link is sent to the current address and the change only takes effect once the user clicks it. Throws KiaviAuthError on failure.
  • setLocale(locale) / setDebugLogger(debug) — update configuration at runtime.

Types

KiaviClient, KiaviSession, KiaviSessionUser, KiaviClientOptions, KiaviAuthenticateOptions, KiaviSignOutOptions, KiaviAuthPolicy, KiaviAuthStateListener, KiaviSessionExpiredError, KiaviBrowserOnlyError, KiaviAuthError, KiaviAuthErrorCode, KiaviResendVerificationEmailOptions, KiaviChangeEmailOptions, KiaviDebugLogger, KiaviDebugLogEntry.

How it works (if you're curious)

The client talks to the Kiavi auth server at authBaseUrl. On first use it fetches /.well-known/kiavi-auth.json to discover the endpoints and capabilities of that server, then transparently uses whichever flow the server is configured for (exchange-mode PKCE or cookie mode) — you don't need to pick one.

Refresh is lazy, not timer-driven: getAccessToken() checks whether the current token is within 30 seconds of expiry and silently mints a new one if so. Concurrent callers share a single in-flight refresh. If all of that fails, the next call to authenticate() sends the user back through login.

The server-side counterpart that verifies the JWTs this client produces is @kiavi/kiavi-js.

This package is browser-only — it depends on window, sessionStorage, and fetch.