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

@witsauth/react-client

v1.3.2

Published

Official React client library for integrating Witsauth Single Sign-On (SSO) authentication or similar services into your React applications.

Readme

@witsauth/react-client

Official React client library for integrating Witsauth Single Sign-On (SSO) authentication or similar services into your React applications.

Installation

npm install @witsauth/react-client
# or
yarn add @witsauth/react-client
# or
pnpm add @witsauth/react-client

Features

  • Complete OAuth2 Authorization Code Flow with PKCE.
  • Hooks (useAuth) for accessing user session state securely.
  • Built-in Axios interceptors for automatic Bearer token injection.
  • Seamless integration with Witsauth Console.
  • Automatic Token Refresh with configurable thresholds.
  • Configurable Storage (localStorage, sessionStorage, or custom).
  • Flexible Routing Redirects for login and logout.

Setup

Wrap your application with the AuthProvider and pass your configuration.

import { AuthProvider, AuthCallback } from '@witsauth/react-client';
import { BrowserRouter, Routes, Route } from 'react-router-dom';

const authConfig = {
  clientId: 'your-client-id',
  authorizationEndpoint: 'https://api.yourdomain.com/auth/authorize',
  tokenEndpoint: 'https://api.yourdomain.com/auth/oauth/token',
  redirectUri: window.location.origin + '/auth/callback',
  scope: 'openid profile email'
};

function App() {
  return (
    <BrowserRouter>
      <AuthProvider config={authConfig}>
        <Routes>
          <Route path="/" element={<Home />} />
          {/* Ensure you map a route for the OAuth callback */}
          <Route path="/auth/callback" element={<AuthCallback />} />
        </Routes>
      </AuthProvider>
    </BrowserRouter>
  );
}

Configuration Options

interface OAuth2Config {
  clientId: string;                    // OAuth2 Client ID
  authorizationEndpoint: string;       // Authorization endpoint URL
  tokenEndpoint: string;               // Token endpoint URL
  redirectUri: string;                 // Redirect URI for callback
  revokeEndpoint?: string;             // Token revocation endpoint (optional)
  userInfoEndpoint?: string;           // OIDC UserInfo endpoint (optional)
  audience?: string;                   // OAuth2 audience parameter (optional)
  scope?: string;                      // OAuth2 scope parameter
  responseType?: string;               // Response type (default: 'code')
  codeChallengeMethod?: 'S256';        // PKCE method (default: 'S256')
  storage?: 'localStorage' | 'sessionStorage' | 'custom'; // Storage strategy
  customStorage?: OAuth2Storage;       // Custom storage implementation
  autoRefresh?: boolean;               // Enable auto token refresh (default: true)
  refreshThreshold?: number;           // Seconds before expiry to refresh (default: 60)
  logLevel?: 'none' | 'error' | 'warn' | 'info' | 'debug'; // Logging level
  nonce?: string;                      // Custom nonce (optional)
  redirectRoute?: string;              // Route to redirect to after login (optional)
  logoutRedirectRoute?: string;        // Route to redirect to after logout (optional)
  oAuthProvider?: 'witsauth' | string; // OAuth provider identifier
  theme?: 'light' | 'dark' | 'system' | (() => 'light' | 'dark' | 'system' | string); // Theme type for hosted pages
}

Usage

Use the useAuth hook to access user state and login/logout functions.

import { useAuth } from '@witsauth/react-client';

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

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

  return (
    <div>
      {isAuthenticated ? (
        <>
          <p>Welcome!</p>
          <button onClick={logout}>Logout</button>
        </>
      ) : (
        <button onClick={login}>Login</button>
      )}
    </div>
  );
}

Account Management

You can seamlessly redirect the user to the Witsauth Account Management console (to update their profile, change password, etc.) by invoking the navigateToAccountManagement() method. This securely POSTs to the IAM backend to preserve the user's active session and safely redirects them back to your application when they are done.

import { useAuth } from '@witsauth/react-client';

function Settings() {
  const { navigateToAccountManagement } = useAuth();

  return (
    <button onClick={navigateToAccountManagement}>
      Manage Account
    </button>
  );
}

Advanced Usage

Custom Storage

You can configure the library to use sessionStorage or provide your own custom storage implementation (e.g., for React Native).

import { OAuth2Storage } from '@witsauth/react-client';

class CustomStorage implements OAuth2Storage {
  getItem(key: string): string | null {
    // Your custom storage logic
    return null;
  }
  
  setItem(key: string, value: string): void {
    // Your custom storage logic
  }
  
  removeItem(key: string): void {
    // Your custom storage logic
  }
}

// Use in configuration
const config = {
  // ... other config
  storage: 'custom',
  customStorage: new CustomStorage()
};

Custom Redirect Routes For Login And Logout

If you want the library to automatically redirect the user after a successful login or logout, you can configure the redirect routes. The library will use window.location.assign to perform a full page navigation.

const authConfig = {
  // ... other config
  redirectRoute: '/dashboard',
  logoutRedirectRoute: '/login'
};

API Interceptors

To automatically attach the Bearer token to your secure API requests, use the setupAxiosInterceptors helper.

import axios from 'axios';
import { setupAxiosInterceptors } from '@witsauth/react-client';

export const apiClient = axios.create({
  baseURL: 'https://api.yourdomain.com'
});

// The interceptor will automatically inject Authorization: Bearer <token>
// Note: You must pass the AuthClient instance, for example from useAuth().client
// setupAxiosInterceptors(apiClient, authClient);