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

transactional-auth-react

v0.1.0

Published

React SDK for Transactional Auth - OpenID Connect authentication for React applications

Downloads

90

Readme

transactional-auth-react

React SDK for Transactional Auth - OpenID Connect authentication for React applications.

Installation

npm install transactional-auth-react
# or
yarn add transactional-auth-react
# or
pnpm add transactional-auth-react

Quick Start

1. Configure the Provider

Wrap your application with the TransactionalAuthProvider:

import { TransactionalAuthProvider } from 'transactional-auth-react';

function App() {
  return (
    <TransactionalAuthProvider
      domain="auth.usetransactional.com"
      clientId="your-client-id"
      redirectUri={window.location.origin}
    >
      <YourApp />
    </TransactionalAuthProvider>
  );
}

2. Add Login/Logout

Use the useAuth hook to access authentication state and methods:

import { useAuth } from 'transactional-auth-react';

function LoginButton() {
  const { isAuthenticated, isLoading, loginWithRedirect, logout, user } = useAuth();

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

  if (isAuthenticated) {
    return (
      <div>
        <span>Welcome, {user?.name}</span>
        <button onClick={() => logout()}>Logout</button>
      </div>
    );
  }

  return <button onClick={() => loginWithRedirect()}>Login</button>;
}

3. Protect Routes

Use the AuthGuard component or withAuthenticationRequired HOC:

import { AuthGuard } from 'transactional-auth-react';

function ProtectedPage() {
  return (
    <AuthGuard fallback={<div>Loading...</div>}>
      <div>This content is only visible to authenticated users</div>
    </AuthGuard>
  );
}

Or with the HOC:

import { withAuthenticationRequired } from 'transactional-auth-react';

function Dashboard() {
  return <div>Dashboard content</div>;
}

export default withAuthenticationRequired(Dashboard);

API Reference

TransactionalAuthProvider

The main provider component that wraps your application.

| Prop | Type | Default | Description | |------|------|---------|-------------| | domain | string | Required | Auth domain (e.g., 'auth.usetransactional.com') | | clientId | string | Required | Your application's client ID | | redirectUri | string | window.location.origin | Redirect URI after authentication | | scope | string | 'openid profile email' | Scopes to request | | audience | string | - | API audience for access token | | cacheLocation | 'memory' \| 'localstorage' | 'localstorage' | Where to store tokens | | useRefreshTokens | boolean | true | Use refresh tokens for silent renewal | | onRedirectCallback | (appState?) => void | - | Callback after redirect from login |

useAuth Hook

Returns the authentication context with state and methods.

const {
  // State
  isAuthenticated,  // boolean - Whether user is authenticated
  isLoading,        // boolean - Whether auth state is loading
  user,             // TransactionalAuthUser | null
  error,            // Error | null

  // Methods
  loginWithRedirect,  // (options?) => Promise<void>
  loginWithPopup,     // (options?) => Promise<void>
  logout,             // (options?) => Promise<void>
  getAccessToken,     // () => Promise<string | undefined>
  getIdTokenClaims,   // () => Promise<object | undefined>
  hasPermission,      // (permission: string) => boolean
  hasRole,            // (role: string) => boolean
} = useAuth();

useUser Hook

Returns the current authenticated user.

const { user, isLoading } = useUser();

useAccessToken Hook

Returns the current access token (or null if not authenticated).

const accessToken = useAccessToken();

AuthGuard Component

Protects content that requires authentication.

<AuthGuard
  fallback={<Loading />}        // Shown while loading
  onUnauthenticated={() => {}}  // Called when not authenticated
  autoRedirect={true}           // Auto-redirect to login
>
  <ProtectedContent />
</AuthGuard>

withAuthenticationRequired HOC

Higher-order component for protecting components.

export default withAuthenticationRequired(Component, {
  fallback: <Loading />,
  onUnauthenticated: () => {},
  returnTo: '/dashboard',
});

Making API Calls

Use the access token to authenticate API requests:

import { useAuth } from 'transactional-auth-react';

function ApiExample() {
  const { getAccessToken } = useAuth();

  async function fetchData() {
    const token = await getAccessToken();

    const response = await fetch('https://api.example.com/data', {
      headers: {
        Authorization: `Bearer ${token}`,
      },
    });

    return response.json();
  }

  // ...
}

Next.js App Router

For Next.js 13+ with the App Router, mark components as client components:

'use client';

import { TransactionalAuthProvider } from 'transactional-auth-react';

export function AuthProvider({ children }: { children: React.ReactNode }) {
  return (
    <TransactionalAuthProvider
      domain="auth.usetransactional.com"
      clientId="your-client-id"
    >
      {children}
    </TransactionalAuthProvider>
  );
}

License

MIT