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

@dapperduckling/oauth-monitor-react

v1.1.3

Published

An opinionated library for securing react apps without all the fuss

Readme

OAuth Monitor for React

This package provides the official React implementation for OAuth Monitor, offering a set of components and hooks that simplify the process of tracking a user's authentication status. It is designed to be flexible and easy to integrate into any React project.

Table of Contents

  1. Getting Started
  2. Overriding UI Components

Getting Started

  1. Installation:

    npm install @dapper-duckling/oauth-monitor-react
  2. Set Up Backend Endpoints:

    For this plugin to work, you must have a backend server that is properly configured to handle authentication requests.

    Important! For more information on how to set up the required endpoints, please refer to the main README file on GitHub.

  3. Wrap your application with the OauthMonitorProvider:

    import { OauthMonitorProvider } from '@dapperduckling/oauth-monitor-react';
    
    const config = {
        client: {
            apiServerOrigin: "http://localhost:3001", // Your backend server
            fastInitialAuthCheck: true,
            eagerRefreshTime: 0.5
        },
        react: {}
    };
    
    function App() {
        return (
            <OauthMonitorProvider config={config}>
                {/* Your application components */}
            </OauthMonitorProvider>
        );
    }
  4. Access authentication status and actions in child components:

    You can access the authentication state and client by using the useOauthMonitor hook.

    import { useOauthMonitor } from '@dapperduckling/oauth-monitor-react';
    
    const MyComponent = () => {
        const [context, dispatch] = useOauthMonitor();
        const client = context.omcClient;
    
        const doLogin = () => client?.handleLogin(true);
        const doLogout = () => client?.handleLogout();
    
        if (context.userStatus.loggedIn) {
            return <button onClick={doLogout}>Logout</button>;
        }
    
        return <button onClick={doLogin}>Login</button>;
    };

Overriding UI Components

By default, this package renders a Material UI based Login Modal, Logout Modal, and "Floating Pill". You can replace these entirely with your own components using the configuration object.

1. Custom Login Modal

The Login Modal is critical for handling authentication flows when tokens expire.

Configuration:

import { MyLoginModal } from './MyLoginModal';

const config = {
    // ... client config
    react: {
        loginModalComponent: MyLoginModal,
        loginModalProps: { title: "App Login" } // Optional
    }
};

Implementation Example:

You should monitor ui.lengthyLogin (triggers after 7s of waiting) and ui.loginError (network failures).

import { useOauthMonitor } from '@dapperduckling/oauth-monitor-react';

export const MyLoginModal = ({ title }) => {
    // 1. Get context
    const [context] = useOauthMonitor();
    const { ui } = context;
    const client = context.omcClient;

    return (
        <div className="modal-overlay">
            <div className="modal-content">
                <h1>{title}</h1>

                {ui.loginError && <p className="error">Server Connection Failed</p>}
                
                {!ui.loginError && ui.lengthyLogin && (
                    <p className="warning">Connecting is taking longer than usual...</p>
                )}

                <button onClick={() => client?.handleLogin(true)}>
                    Log In
                </button>
            </div>
        </div>
    );
};

2. Custom Logout Modal

Overrides the confirmation dialog shown before logging out.

Configuration:

import { MyLogoutModal } from './MyLogoutModal';

const config = {
    react: {
        logoutModalComponent: MyLogoutModal
    }
};

Implementation Example:

import { useOauthMonitor, OmcDispatchType } from '@dapperduckling/oauth-monitor-react';

export const MyLogoutModal = () => {
    const [context, dispatch] = useOauthMonitor();
    const client = context.omcClient;

    const handleLogout = () => {
        dispatch({ type: OmcDispatchType.EXECUTING_LOGOUT });
        client?.handleLogout();
    };

    const handleCancel = () => {
        dispatch({ type: OmcDispatchType.HIDE_DIALOG });
        client?.abortAuthCheck();
    };

    return (
        <div className="modal">
            <p>Sign out of your account?</p>
            <button onClick={handleLogout}>Confirm</button>
            <button onClick={handleCancel}>Cancel</button>
        </div>
    );
};

3. Custom Floating Pill

Overrides the small indicator shown to non-logged-in users.

Configuration:

import { MyPill } from './MyPill';

const config = {
    react: {
        floatingPillComponent: MyPill
    }
};

Implementation Example:

import { useOauthMonitor, OmcDispatchType } from '@dapperduckling/oauth-monitor-react';

export const MyPill = () => {
    const [context, dispatch] = useOauthMonitor();
    const client = context.omcClient;

    const openLogin = () => {
        dispatch({ type: OmcDispatchType.SHOW_LOGIN });
        client?.handleLogin(true);
    };

    return (
        <button className="sticky-login-btn" onClick={openLogin}>
            Not Logged In - Click to Login
        </button>
    );
};