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

@kolaylogin/react

v0.3.9

Published

React provider, hooks, and components for KolayLogin. Includes <SignedIn>, <SignedOut>, <Protect>, useAuth, useUser, useOrganization, and more.

Readme

@kolaylogin/react

React SDK for KolayLogin. Provides a <KolayLoginProvider />, hooks for session state, and a background refresh loop that keeps the short-lived __session JWT valid without interrupting your UI.

Install

npm install @kolaylogin/react

Requires React 18 or newer.

Quick start

// app.tsx
import { KolayLoginProvider } from '@kolaylogin/react';

export default function App({ children }: { children: React.ReactNode }) {
  return (
    <KolayLoginProvider baseUrl={process.env.REACT_APP_KL_API_URL!}>
      {children}
    </KolayLoginProvider>
  );
}
// any component
import { useSession, useUserId } from '@kolaylogin/react';

export function Avatar() {
  const session = useSession();
  const userId = useUserId();

  if (session.status === 'signed_out') return <SignInButton />;
  return <span>Signed in as {userId}</span>;
}

API

<KolayLoginProvider />

| Prop | Type | Default | Description | | --------------------- | --------- | ------- | ---------------------------------------------------------------------------- | | baseUrl | string | — | Instance API base URL (e.g. https://auth.example.com). | | autoRefresh | boolean | true | Runs the refresh loop in the background to keep __session fresh. | | refreshSkewSeconds | number | 15 | How many seconds before JWT expiry to trigger a refresh. |

The provider reads the __session cookie on mount, decodes its claims, and exposes them to descendants. When autoRefresh is on, it schedules a refresh that fires refreshSkewSeconds before exp and repeats for the lifetime of the session.

Hooks

  • useSession() — returns { status: 'signed_in', jwt, claims } | { status: 'signed_out' }.
  • useUserId() — returns the sub claim when signed in, otherwise null.
  • useKolayLogin() — returns { client, session, refresh }. refresh() lets you trigger a token refresh manually (e.g. after a password change).

Low-level client

KolayLoginReactClient is exposed if you want to skip the provider — useful for scripts or non-React roots. Most apps should not need it.

How the refresh loop works

Your instance issues two cookies:

  • __client (httpOnly, long-lived) — held by the browser, used only for the refresh call.
  • __session (readable by JS, ~60s) — the JWT your frontend sends to your backend.

The SDK decodes __session.exp, schedules setTimeout(refresh, exp - skew), hits the instance's /v1/auth/refresh endpoint, and re-reads the new __session cookie. The httpOnly __client never touches JS memory. If the refresh fails (revoked, network error), state transitions to signed_out and children re-render.

Next.js + Server Components

This package is a Client SDK ('use client' under the hood). For App Router middleware and server-side session access, use @kolaylogin/nextjs.

Error handling

  • useSession() never throws — it simply reports signed_out when the cookie is missing or invalid.
  • Manual refresh() can throw network errors; wrap it in a try/catch if you surface retry UI.

License

MIT