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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@dashnex.com/auth-react

v0.0.26

Published

DashNex React Auth

Readme

DashNex OAuth Client

A TypeScript OAuth 2.0 client implementation for DashNex authentication, supporting both standard OAuth flow and PKCE (Proof Key for Code Exchange).

Features

  • OAuth 2.0 Authorization Code Flow
  • PKCE Support for Enhanced Security
  • Token Storage Management
  • TypeScript Support
  • React Hooks and Components
  • Configurable Base URL for testing
  • Automatic Token Refresh

Get OAuth Client credentials

  1. Create a product on DashNex (Hosting app), create Variant: Access, Hosting app, 1
  2. Go to Product Info -> OAuth clients, Create client. Set Redirect URI, choose Variant, Grant type: Authorization code

Installation

npm install @dashnex.com/auth-react
# or
yarn add @dashnex.com/auth-react

Usage with React

Basic Setup

  1. First, wrap your application with the DashNexAuthProvider:
import { DashNexAuthProvider, useAuthLocalStorage } from "@dashnex.com/auth-react";

export default function App() {
  const config = {
    clientId: "your-client-id",
    redirectUri: "https://your-app.com/callback",
    baseUrl: "https://dashnex.com", // Optional, defaults to https://dashnex.com
    tokenStorage: useAuthLocalStorage("your-app-name"), // Use your own unique name
  };

  return (
    <DashNexAuthProvider config={config}>
      <YourApp />
    </DashNexAuthProvider>
  );
}
  1. Use the useAuth hook in your components:
import { useAuth, LoginWithDashnexButton } from "@dashnex.com/auth-react";

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

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

  return (
    <div>
      {user ? (
        <div>
          <h1>Welcome, {user.firstName}</h1>
          <button onClick={logout}>Logout</button>
        </div>
      ) : (
        <div>
          <LoginWithDashnexButton />
          {/* or */}
          <button onClick={login}>Login with DashNex</button>
        </div>
      )}
    </div>
  );
}

Usage with Vanilla JavaScript

  1. Include the library in your HTML:
<script src="https://cdn.jsdelivr.net/npm/@dashnex.com/auth-react@latest/dist/browser.global.js"></script>
  1. Initialize and use the client:
const { DashNexOauthClient, createAuthLocalStorage } = DashNex;

// Initialize the client
const client = new DashNexOauthClient({
  clientId: "your-client-id",
  redirectUri: "https://your-app.com/callback",
  tokenStorage: createAuthLocalStorage("your-app-name"),
  baseUrl: "https://dashnex.com", // Optional
});

// Handle login
function startLogin() {
  window.location.href = client.getAuthorizationUrl();
}

// Handle logout
async function logout() {
  await client.logout();
}

// Handle the OAuth callback
const urlParams = new URLSearchParams(window.location.search);
const code = urlParams.get("code");

if (code) {
  try {
    await client.exchangeCodeForToken(code);
    // Clean up the URL
    window.history.replaceState({}, document.title, window.location.pathname);
    
    // Get user information
    const user = await client.getCurrentUser();
    
    console.log("Logged in user:", user);
  } catch (error) {
    console.error("Authentication error:", error);
  }
}

Configuration Options

| Parameter | Type | Required | Description | |-----------|------|----------|-------------| | clientId | string | Yes | Your OAuth client ID | | clientSecret | string | No | Your OAuth client secret (not required for PKCE flow) | | redirectUri | string | Yes | Your application's callback URL | | baseUrl | string | No | DashNex API base URL (defaults to https://dashnex.com) | | tokenStorage | TokenStorage | Yes | Implementation for token storage |

Token Storage

The library provides two token storage implementations:

  1. useAuthLocalStorage - For React applications using localStorage
  2. createAuthLocalStorage - For Vanilla JavaScript applications using localStorage

Both implementations handle:

  • Access token storage
  • Refresh token storage
  • PKCE code verifier storage
  • State parameter storage for security

Development

npm run serve
# or
yarn serve
# or
bun run serve

Open example.html file and set up your OAuth client.

Security Considerations

  • The library supports PKCE (Proof Key for Code Exchange) for enhanced security
  • All tokens are stored securely in localStorage with a unique prefix
  • State parameters are used to prevent CSRF attacks
  • Automatic token refresh is handled internally

License

MIT License - See LICENSE file for details