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

@nishant625/auth-react

v0.2.0

Published

React SDK for easy-auth OAuth2/PKCE authentication

Readme

@nishant625/auth-react

React SDK for OAuth 2.0 + PKCE authentication. Works with Sentinel or any OIDC-compatible auth server.

Install

npm install @nishant625/auth-react

Setup

Wrap your app in <AuthProvider>:

// main.jsx
import { AuthProvider } from '@nishant625/auth-react'

<AuthProvider
  clientId="clt_your_client_id"
  authServerUrl="http://localhost:4000"
  redirectUri="http://localhost:5173/callback"
>
  <App />
</AuthProvider>

| Prop | Required | Description | |---|---|---| | clientId | ✓ | Your registered client ID | | authServerUrl | ✓ | Base URL of the auth server | | redirectUri | ✓ | Must match a registered redirect URI | | clientSecret | — | Only for confidential server-side clients — never put this in a SPA |

Usage

import { useAuth } from '@nishant625/auth-react'

function App() {
  const { isAuthenticated, isLoading, user, login, logout, getAccessToken } = useAuth()

  if (isLoading) return null

  if (!isAuthenticated) {
    return <button onClick={login}>Sign in</button>
  }

  return (
    <div>
      <p>Hello {user.email}</p>
      <button onClick={logout}>Sign out</button>
    </div>
  )
}

useAuth() reference

| Value | Type | Description | |---|---|---| | isAuthenticated | boolean | Whether the user is logged in | | isLoading | boolean | True during initial session check and callback processing | | user | object \| null | Decoded JWT payload — { sub, email, scope, exp, ... } | | login() | () => void | Redirects to the auth server login page | | logout() | () => void | Clears tokens from storage, resets state | | getAccessToken() | () => Promise<string \| null> | Returns a valid JWT, silently refreshing if expired |

Making authenticated API calls

getAccessToken() is async — it checks expiry and silently refreshes if needed.

const { getAccessToken } = useAuth()

const res = await fetch('/api/me', {
  headers: {
    Authorization: `Bearer ${await getAccessToken()}`
  }
})

How it works

  1. login() generates a PKCE code_verifier + code_challenge (SHA-256), stores the verifier in sessionStorage, and redirects to the auth server
  2. After login the auth server redirects back with ?code=...&state=...
  3. AuthProvider detects the code on mount, verifies state (CSRF protection), exchanges the code for tokens via POST /oauth/token
  4. Tokens are stored, JWT is decoded to populate user, URL is cleaned up
  5. On page reload, the access token is restored from storage and decoded back into user

Token storage note

Access token and refresh token are stored in localStorage. This is simple but means XSS can read them. For higher security, keep the access token in memory and the refresh token in an HttpOnly cookie set by a backend proxy.