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-react-native

v0.2.0-alpha.0

Published

Kiavi React Native authentication client

Readme

@kiavi/kiavi-react-native

Kiavi authentication for React Native apps (Expo and bare React Native, iOS and Android).

Speaks the same /api/auth/exchange/* wire protocol as @kiavi/kiavi-browser. PKCE only — no client secrets. Refresh tokens are stored in the OS keychain (iOS Keychain / Android Keystore) via expo-secure-store.

Install

pnpm add @kiavi/kiavi-react-native expo-auth-session expo-secure-store expo-crypto

expo-auth-session brings expo-web-browser in transitively; if you have a bare workflow that pins peer deps, install it explicitly too.

After install, the package automatically writes its version-pinned integration guide to .kiavi/kiavi-react-native.md and adds a reference block to your repo's AGENTS.md (or CLAUDE.md). If your package manager blocks dependency scripts, run npx kiavi-react-native init for a manual refresh and approval guidance. See AI agent docs for the full picture.

Configure your app's URL scheme

The SDK discovers your app slug from the auth server and derives its redirect URI from it. An app with slug acme redirects to acme://auth, and the auth server only allows that scheme prefix for its derived acme-native client. Add the matching scheme to app.json:

{
  "expo": {
    "scheme": "acme",
    "ios": {
      "bundleIdentifier": "com.acme.app"
    },
    "android": {
      "package": "com.acme.app"
    }
  }
}

If you need a different scheme or a Universal Link / App Link, pass redirectUri explicitly to the constructor. Whatever you pass must match an entry in the client's allowed_origins (configured in the Kiavi management UI).

Initialize

import { KiaviClient } from '@kiavi/kiavi-react-native'

export const kiavi = new KiaviClient({
  authBaseUrl: 'https://auth.acme.kiavi.eu',
  // redirectUri: 'acme://auth' — derived automatically
})

Sign in

import { Button } from 'react-native'
import { kiavi } from '@/lib/kiavi'
import { useRouter } from 'expo-router'

export default function SignInScreen() {
  const router = useRouter()
  return (
    <Button
      title='Sign in'
      onPress={async () => {
        const session = await kiavi.authenticate()
        router.replace('/home')
      }}
    />
  )
}

authenticate() is idempotent: if a session is already live or silently refreshable from secure storage, it returns immediately. Otherwise it opens the system browser (SFSafariViewController on iOS, Custom Tabs on Android) and resolves once the user returns.

Call your API

const token = await kiavi.getAccessToken()
const res = await fetch('https://api.acme.com/me', {
  headers: { Authorization: `Bearer ${token}` },
})

getAccessToken() refreshes automatically when the access token has less than 30 seconds of life left. Concurrent callers share one in-flight refresh — there is no need to debounce yourself.

If there is no session and refresh fails, it throws KiaviSessionExpiredError. Catch that and call authenticate() to start a new sign-in flow.

React to session changes

useEffect(() => {
  return kiavi.onAuthStateChange((session) => {
    if (!session) router.replace('/sign-in')
  })
}, [])

The listener fires on every successful sign-in, every refresh, every sign-out, and every refresh failure that clears the session (for example, when the user revokes this device from another device). It does NOT fire synchronously on subscription — call getSession() first if you need the current state.

Sign out

await kiavi.signOut()

Revokes the refresh token server-side, wipes secure storage, and notifies listeners. There is no browser redirect on mobile — handle navigation yourself.

Errors

import { KiaviAuthError, KiaviSessionExpiredError } from '@kiavi/kiavi-react-native'

try {
  const token = await kiavi.getAccessToken()
} catch (err) {
  if (err instanceof KiaviSessionExpiredError) {
    // No valid session and refresh failed — kick the user to sign-in.
    await kiavi.authenticate()
    return
  }
  if (err instanceof KiaviAuthError) {
    // err.code: 'rate_limited' | 'invalid_request' | 'unauthenticated'
    //         | 'server_error' | 'network_error' | 'unknown'
    // err.status, err.retryAfterSeconds
  }
}

Network errors (offline, DNS failure) surface as KiaviAuthError with code: 'network_error' and status: 0. They never wipe the user's saved refresh token — only an unauthenticated (401) response from /refresh does that, since it means the chain has been server-side revoked.

Bare React Native (non-Expo) notes

expo-auth-session, expo-secure-store, expo-crypto, and expo-web-browser all support bare RN via expo install. Follow each package's installation steps; no other changes are needed.

Debug logging

new KiaviClient({
  authBaseUrl: '...',
  debug: true, // logs to console
  // or pass a function: debug: (entry) => myLogger.log(entry)
})