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-client

v2.0.2

Published

An opinionated library securing frontend applications without all the fuss

Readme

OAuth Monitor Client

This package provides a UI-agnostic client for the OAuth Monitor. It handles the core logic of checking authentication status, managing tokens, and communicating with your backend server. It's designed to be used as a standalone library that you can integrate into any JavaScript application, allowing you to build your own custom UI on top of it. It operates by periodically checking a user-status endpoint on your server and emitting events when the user's authentication state changes. This allows you to create a responsive UI that reacts to logins, logouts, and token refreshes.

Table of Contents

  1. Getting Started
  2. API and Events

Getting Started

  1. Installation:

    npm install @dapperduckling/oauth-monitor-client
  2. Set Up Backend Endpoints:

    For this client 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. Initialize and Use the Client:

    The client is event-driven. You can listen for events to update your UI and application state.

    import { OauthMonitorClient } from '@dapperduckling/oauth-monitor-client';
    
    // Configuration for the client
    const config = {
        apiServerOrigin: 'http://localhost:3001', // Your backend server
        fastInitialAuthCheck: true,
        eagerRefreshTime: 0.5,
    };
    
    // Create a new instance of the client
    const oauthClient = new OauthMonitorClient(config);
    
    // Example: Update UI based on authentication status
    oauthClient.on('userStatusChange', (status) => {
        const { loggedIn } = status;
        if (loggedIn) {
            console.log('User is logged in!');
            // Update your UI to show a logged-in state
        } else {
            console.log('User is logged out.');
            // Update your UI to show a logged-out state
        }
    });
    
    // Example: Manually trigger login or logout
    function handleLogin() {
        oauthClient.handleLogin();
    }
    
    function handleLogout() {
        oauthClient.handleLogout();
    }
    
    // Start the client's monitoring
    oauthClient.start();

API and Events

OauthMonitorClient(config)

Creates a new client instance. The config object requires apiServerOrigin.

.start()

Starts the client's polling mechanism to check for authentication status changes.

.stop()

Stops the client's polling mechanism.

.handleLogin()

Initiates the login flow by opening a new window to the login endpoint.

.handleLogout()

Initiates the logout flow by redirecting the user to the logout endpoint.

Events

You can listen for events using the .on(eventName, callback) method.

  • userStatusChange: Fired when the user's authentication status changes. The callback receives the new userStatus object.
  • tokenRefresh: Fired when the access token is about to expire and a refresh is attempted.
  • error: Fired when an error occurs during the authentication check.