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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@bharat-ebiz/auth

v1.0.155

Published

React authentication provider with OAuth2/PKCE support, token management, and pre-built hooks/components

Readme

Auth Provider

npm version
License: MIT

A React authentication provider package for integrating OAuth 2.0 / PKCE authentication into your React applications. Provides hooks, components, and token management utilities.


Features

  • 🔐 OAuth 2.0 & PKCE Support – Secure authentication with PKCE flow
  • ⚛️ React Context Provider – Easy state management with React hooks
  • 🎨 Pre-built Components – Ready-to-use buttons and UI elements
  • 📱 Popup & Redirect Flow – Supports both popup and full redirect authentication
  • 🔄 Automatic Token Management – Token storage, refresh handling, and retrieval
  • 📦 TypeScript Support – Full type definitions included
  • 🎯 Tree Shakable – Import only what you need

Installation

Install the latest version:

npm install @bharat-ebiz/auth-provider
# or
yarn add @bharat-ebiz/auth-provider
# or
pnpm add @bharat-ebiz/auth-provider

Install the next pre-release version:

npm install @bharat-ebiz/auth-provider@next
# or
yarn add @bharat-ebiz/auth-provider@next
# or
pnpm add @bharat-ebiz/auth-provider@next

Quick Start

Wrap your app with AuthProvider

import { AuthProvider } from "@bharat-ebiz/auth-provider";

function App() {
  return (
    <AuthProvider
      config={{
        clientId: "your-client-id",
        redirectUri: "http://localhost:3000/callback",
        prompt: true,
        scope: "openid profile email",
      }}
      onAuthStateChange={(isAuth, user) => {
        console.log("Auth state:", isAuth, user);
      }}
      onError={(error) => {
        console.error("Auth error:", error);
      }}
    >
      <YourApp />
    </AuthProvider>
  );
}

Use the authentication hook

import { useAuth, Button } from "@bharat-ebiz/auth-provider";

function YourApp() {
  const { isAuthenticated, isLoading, user, login, logout } = useAuth();

  if (isLoading) return <div>Loading...</div>;

  return (
    <div>
      {isAuthenticated ? (
        <div>
          <h1>Welcome {user?.name}!</h1>
          <Button variant="outline" onClick={logout}>
            Logout
          </Button>
        </div>
      ) : (
        <Button onClick={login}>Login</Button>
      )}
    </div>
  );
}

Components

AuthProvider

Manages authentication state for your app.

<AuthProvider
  config={{
    clientId: string;           // Required
    redirectUri: string;        // Required
    clientSecret?: string;      // Optional
    scope?: string;             // Optional
    state?: string;             // Optional
    prompt?: boolean;           // Optional
    usePKCE?: boolean;          // Optional
    codeChallengeMethod?: 'S256' | 'plain'; // Optional
  }}
  onAuthStateChange?={(isAuth, user) => void}
  onError?={(error) => void}
/>

Button

Pre-styled authentication button.

import { Button } from "@bharat-ebiz/auth-provider";

<Button variant="default">Default</Button>
<Button variant="outline">Outline</Button>
<Button variant="destructive">Destructive</Button>
<Button variant="secondary">Secondary</Button>
<Button variant="ghost">Ghost</Button>
<Button variant="link">Link</Button>

Hooks

useAuth()

Provides authentication state and utility methods:

const {
  isAuthenticated,
  isLoading,
  user,
  accessToken,
  login,
  logout,
  apiCall,
  refreshAuthState,
  getAccessToken,
  storeTokens,
} = useAuth();

API Reference

Making API Calls

const { apiCall } = useAuth();

const userData = await apiCall("/api/user");

Environment Variables

VITE_AUTH_CLIENT_ID=your_client_id
VITE_AUTH_REDIRECT_URI=http://localhost:3000/callback

License

MIT © Bharat Makwana