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

@vergeinfosoft/react

v1.0.6

Published

React SDK for Verge Auth - Single-line authentication integration

Readme

@vergeinfosoft/react

React SDK for Verge Auth - Single-line authentication integration for your React applications.

Installation

npm install @vergeinfosoft/react

Quick Start

One-Line Integration

Wrap your entire app with the VergeAuth component:

import { VergeAuth } from '@vergeinfosoft/react';

function App() {
  return (
    <VergeAuth>
      <YourApp />
    </VergeAuth>
  );
}

That's it! Your app is now protected with Verge Auth.

With Custom Configuration

import { VergeAuth } from '@vergeinfosoft/react';

function App() {
  return (
    <VergeAuth 
      config={{
        apiBaseUrl: '/api',
        authEndpoint: '/auth/me',
        loginUrl: 'https://app.vergeauth.in/login',
        logoutUrl: '/auth/logout',
        redirectUrl: window.location.origin
      }}
      callbackPath="/auth/callback"
    >
      <YourApp />
    </VergeAuth>
  );
}

Environment Variables

Set these in your .env file:

VITE_VERGEAUTH_LOGIN_URL=https://app.vergeauth.in/login

Advanced Usage

Using Individual Components

If you need more control, you can use the individual components:

import { AuthProvider, useAuth, ProtectedRoute } from '@vergeinfosoft/react';
import { BrowserRouter, Routes, Route } from 'react-router-dom';

function App() {
  return (
    <AuthProvider>
      <BrowserRouter>
        <Routes>
          <Route path="/auth/callback" element={<AuthCallback />} />
          <Route path="/*" element={
            <ProtectedRoute>
              <YourApp />
            </ProtectedRoute>
          } />
        </Routes>
      </BrowserRouter>
    </AuthProvider>
  );
}

Permission-Based Route Protection

import { ProtectedRoute } from '@vergeinfosoft/react';

function Dashboard() {
  return (
    <ProtectedRoute requiredPermissions={['hrms-service:/api/dashboard/stats:get']}>
      <DashboardContent />
    </ProtectedRoute>
  );
}

Using the Auth Hook

import { useAuth } from '@vergeinfosoft/react';

function UserProfile() {
  const { isAuthenticated, loading, permissions, hasPermission, login, logout } = useAuth();

  if (loading) return <div>Loading...</div>;

  if (!isAuthenticated) {
    return <button onClick={login}>Login</button>;
  }

  return (
    <div>
      <h1>Welcome!</h1>
      <p>Permissions: {permissions.join(', ')}</p>
      {hasPermission('admin') && <button>Admin Panel</button>}
      <button onClick={logout}>Logout</button>
    </div>
  );
}

Require All Permissions

By default, ProtectedRoute requires ANY of the specified permissions. To require ALL:

<ProtectedRoute 
  requiredPermissions={['perm1', 'perm2']} 
  requireAll={true}
>
  <AdminPanel />
</ProtectedRoute>

Custom Fallback Path

<ProtectedRoute 
  requiredPermissions={['admin']} 
  fallbackPath="/unauthorized"
>
  <AdminPanel />
</ProtectedRoute>

API Reference

VergeAuth

Main wrapper component for one-line integration.

Props:

  • children (ReactNode): Your application
  • config? (VergeAuthConfig): Configuration object
  • callbackPath? (string): Path for auth callback (default: /auth/callback)

AuthProvider

Provides auth context to your app.

Props:

  • children (ReactNode): Child components
  • config? (VergeAuthConfig): Configuration object

ProtectedRoute

Protects routes based on authentication and permissions.

Props:

  • children (ReactNode): Protected content
  • requiredPermissions? (string[]): Required permissions
  • requireAll? (boolean): Require all permissions instead of any (default: false)
  • fallbackPath? (string): Redirect path if unauthorized (default: /)

AuthCallback

Handles OAuth callback from Verge Auth.

Props:

  • redirectPath? (string): Path to redirect after successful auth (default: /)

useAuth

Hook to access auth state and methods.

Returns:

  • isAuthenticated (boolean | null): Authentication status
  • loading (boolean): Loading state
  • permissions (string[]): User permissions
  • appBrandName (string | null): App brand name
  • user (any): User data
  • hasPermission(permission: string) (function): Check if user has permission
  • hasAnyPermission(permissions: string[]) (function): Check if user has any of the permissions
  • login() (function): Redirect to login
  • logout() (function): Redirect to logout

Configuration

VergeAuthConfig

interface VergeAuthConfig {
  apiBaseUrl?: string;        // Default: '/api'
  authEndpoint?: string;      // Default: '/auth/me'
  loginUrl?: string;          // Default: from VITE_VERGEAUTH_LOGIN_URL
  logoutUrl?: string;         // Default: '/auth/logout'
  redirectUrl?: string;       // Default: current URL
}

How It Works

  1. Auth Check: On mount, the SDK calls /api/auth/me to check authentication status
  2. 403 Handling: A 403 response means the user is authenticated but lacks route permission
  3. Login Redirect: Unauthenticated users are redirected to the Verge Auth login page
  4. Callback Handling: After login, the callback route handles the OAuth code exchange
  5. Permission Checks: Routes can be protected based on user permissions

Backend Requirements

Your backend must:

  • Use the Verge Auth Python SDK with add_central_auth(app)
  • Provide an /api/auth/me endpoint (handled automatically by the SDK)
  • Handle OAuth code exchange at /api/?code= (handled automatically by the SDK)

Example: Full HRMS Integration

import { VergeAuth, ProtectedRoute, useAuth } from '@vergeinfosoft/react';

const PERMISSIONS = {
  DASHBOARD_GET: "hrms-service:/api/dashboard/stats:get",
  EMPLOYEES_GET: "hrms-service:/api/employees:get",
  ATTENDANCE_GET: "hrms-service:/api/attendance:get",
};

function App() {
  return (
    <VergeAuth>
      <Dashboard />
      <Employees />
      <Attendance />
    </VergeAuth>
  );
}

function Dashboard() {
  return (
    <ProtectedRoute requiredPermissions={[PERMISSIONS.DASHBOARD_GET]}>
      <DashboardContent />
    </ProtectedRoute>
  );
}

function Employees() {
  return (
    <ProtectedRoute requiredPermissions={[PERMISSIONS.EMPLOYEES_GET]}>
      <EmployeesContent />
    </ProtectedRoute>
  );
}

License

MIT

Support

For issues and questions, please contact Verge Infosoft support.