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

@brandwacht/sso-auth-react

v0.0.1

Published

BWH SSO authentication library for React apps

Readme

@brandwacht/sso-auth-react

Drop-in SSO authentication library for React apps in the Brandwacht Huren B.V. ecosystem.

React port of @brandwacht/sso-auth (Angular). Same SSO portal, same backend contract, same sessionStorage keys — so a React app and the existing Angular apps share one SSO session and silently log each other in.

Installation

npm install @brandwacht/sso-auth-react react-router-dom

Peer dependencies: react ^18, react-dom ^18, react-router-dom ^6.

Import the stylesheet once at your app entry:

import '@brandwacht/sso-auth-react/styles.css';

Quick start

1. Wrap your app

// main.tsx
import { BrowserRouter, Routes, Route } from 'react-router-dom';
import {
  BwhSsoAuthProvider,
  BwhSsoLoginPage,
  RequireBwhAuth,
  type BwhSsoAuthConfig,
} from '@brandwacht/sso-auth-react';
import '@brandwacht/sso-auth-react/styles.css';
import { Dashboard } from './Dashboard';

const ssoConfig: BwhSsoAuthConfig = {
  ssoAuthPortalUri: import.meta.env.VITE_SSO_PORTAL_URI,
  apiBaseUrl: import.meta.env.VITE_API_BASE_URL,
  appBaseUrl: import.meta.env.VITE_APP_BASE_URL,
  appId: 'my-react-app',
  resolveLanding: () => '/dashboard',
};

export function App() {
  return (
    <BwhSsoAuthProvider config={ssoConfig}>
      <BrowserRouter>
        <Routes>
          <Route path="/login" element={<BwhSsoLoginPage />} />
          <Route
            element={
              <RequireBwhAuth>
                <AppLayout />
              </RequireBwhAuth>
            }
          >
            <Route path="/dashboard" element={<Dashboard />} />
            <Route path="*" element={<Navigate to="/dashboard" replace />} />
          </Route>
        </Routes>
      </BrowserRouter>
    </BwhSsoAuthProvider>
  );
}

Define ssoConfig at module scope (or wrap in useMemo) — passing a fresh object every render will recreate every callback the library exposes.

2. Read auth state and call your API

import { useBwhSsoAuth, useBwhAuthFetch } from '@brandwacht/sso-auth-react';

function Header() {
  const { user, logout } = useBwhSsoAuth();
  return (
    <header>
      <span>{user?.email}</span>
      <button onClick={logout}>Sign out</button>
    </header>
  );
}

function ProfileCard() {
  const authFetch = useBwhAuthFetch();
  const [me, setMe] = useState<Me | null>(null);
  useEffect(() => {
    authFetch('/api/me').then((r) => r.json()).then(setMe);
  }, [authFetch]);
  // ...
}

For non-React code paths (e.g. configuring an axios instance at module load):

import axios from 'axios';
import { getStoredBwhAuthToken } from '@brandwacht/sso-auth-react';

const api = axios.create({ baseURL: '/api' });
api.interceptors.request.use((config) => {
  const token = getStoredBwhAuthToken();
  if (token) config.headers.Authorization = `Bearer ${token}`;
  return config;
});

Multi-app SSO across Angular + React

This library is wire-compatible with the Angular @brandwacht/sso-auth library:

| Concern | Shared contract | | -------------------- | ---------------------------------------------- | | SSO portal flow | redirect → ?sso_code=…POST /api/sso/exchangePOST {api}/auth/sso | | Auth storage | sessionStorage['BWH_SSO_AUTH_STATE'] | | Silent SSO flag | sessionStorage['bwh_sso_silent_attempted'] | | Return-URL handoff | sessionStorage['bwh_sso_return_url'] | | Cross-app logout | parent-domain cookie bwh_sso=1 | | UI prefs | localStorage['bwh.ui.lang'], bwh.ui.theme.dark |

A user logged in to any Angular app will be silently authenticated in your React app on first visit, and vice versa. Make sure all apps use the same ssoAuthPortalUri and that each app's appId + appBaseUrl is whitelisted in the portal.

API

<BwhSsoAuthProvider config={...}>

Top-level provider that wires up auth state, i18n, and theme.

useBwhSsoAuth()

{
  token: string | null;
  user: SsoAuthUser | null;
  isAuthenticated: boolean;
  startSsoLogin(): void;
  startSilentSsoLogin(): void;
  ssoLogin(code: string): Promise<{ token; user }>;
  logout(): void;
  updateStoredUser(user: SsoAuthUser): void;
}

useBwhAuthFetch()

Returns a fetch-compatible function that injects Authorization: Bearer <token> when authenticated.

<RequireBwhAuth>

Route guard for react-router-dom. Renders children when authenticated, otherwise navigates to the configured loginRoute with ?returnUrl=… preserved.

<BwhSsoLoginPage>

The full pre-built login page. Handles the SSO callback, silent SSO, and renders the dark/light themed UI with EN/NL switcher.

useBwhI18n() / useBwhTranslate()

const { lang, setLanguage, t, registerTranslations } = useBwhI18n();
// or, just the translator:
const t = useBwhTranslate();

Use registerTranslations('nl', { 'My key': 'Mijn vertaling' }) to add app-specific strings; they override the built-in dictionary.

useBwhTheme()

const { isDark, toggle, setDark } = useBwhTheme();

The theme provider toggles class="dark" on <html>. Pair with Tailwind's darkMode: 'class' if you use Tailwind.

getStoredBwhAuthToken(storageKey?)

Read the persisted JWT directly. For module-level setup outside React.

BwhHttpError

Thrown by the internal SSO HTTP helpers. Has { status, error } matching the shape humanizeBwhAuthError reads.

humanizeBwhAuthError(err, t)

Convert a thrown error from ssoLogin() into a user-readable string. Mirrors the Angular library's error handling exactly.

Configuration reference

interface BwhSsoAuthConfig {
  ssoAuthPortalUri: string;        // e.g. 'https://oauth-portal.bwh.nl'
  apiBaseUrl: string;              // e.g. '/api'
  appBaseUrl: string;              // e.g. 'https://my-app.bwh.nl'
  appId: string;                   // unique id registered in the SSO portal
  storageKey?: string;             // default 'BWH_SSO_AUTH_STATE'
  loginRoute?: string;             // default '/login'
  ssoCodeParam?: string;           // default 'sso_code'
  ssoEndpoint?: string;            // default '/auth/sso'
  resolveLanding: (user: SsoAuthUser) => string | Promise<string>;
}

Development

npm install
npm run typecheck
npm run build       # tsup → dist/{index.js,index.cjs,index.d.ts,styles.css}