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

@auth-gate/react

v0.7.1

Published

React SDK for [AuthGate](https://authgate.dev) — drop-in authentication with OAuth, email, SMS, and MFA for React apps using Hono as the backend.

Readme

@auth-gate/react

React SDK for AuthGate — drop-in authentication with OAuth, email, SMS, and MFA for React apps using Hono as the backend.

Installation

npm install @auth-gate/react

Peer dependencies: react >= 18, hono >= 4

Quick Start

1. Create Auth Routes (Server)

// server/auth.ts
import { createAuthRoutes } from "@auth-gate/react/server";

const auth = createAuthRoutes({
  apiKey: process.env.AUTHGATE_API_KEY!,
  baseUrl: "https://authgate.dev",
  appUrl: "http://localhost:3000",
});

2. Mount in Hono

// server/index.ts
import { Hono } from "hono";
import { auth } from "./auth";

const app = new Hono();
app.route("/api/auth", auth);

export default app;

3. Add the Provider (Client)

// src/App.tsx
import { AuthProvider } from "@auth-gate/react";

export default function App() {
  return (
    <AuthProvider>
      <Router />
    </AuthProvider>
  );
}

4. Use the Hooks

import { useAuth } from "@auth-gate/react";

function Profile() {
  const { user, loading, logout } = useAuth();

  if (loading) return <p>Loading...</p>;
  if (!user) return <p>Not signed in</p>;

  return (
    <div>
      <p>Hello, {user.name}</p>
      <button onClick={logout}>Sign out</button>
    </div>
  );
}

Route Map

The Hono router registers these routes under your mount path (e.g. /api/auth/):

| Method | Route | Description | |--------|-------|-------------| | GET | /:provider/login | Start OAuth flow (google, github, discord, azure, apple) | | GET | /callback | OAuth / magic link callback | | POST | /email/signup | Email registration | | POST | /email/signin | Email sign-in | | POST | /email/forgot-password | Request password reset | | POST | /email/reset-password | Confirm password reset | | POST | /email/verify-code | Verify email with OTP | | POST | /magic-link/send | Send magic link | | POST | /sms/send-code | Send SMS code | | POST | /sms/verify-code | Verify SMS code | | POST | /mfa/verify | Complete MFA challenge | | POST | /refresh | Refresh session token | | POST | /logout | Sign out and revoke session | | GET | /me | Get current user |

Client Components

<AuthProvider>

Wraps your app and manages auth state via context.

<AuthProvider
  meEndpoint="/api/auth/me"       // default
  logoutEndpoint="/api/auth/logout" // default
>
  {children}
</AuthProvider>

| Prop | Type | Default | Description | |------|------|---------|-------------| | meEndpoint | string | "/api/auth/me" | Endpoint to fetch current user | | logoutEndpoint | string | "/api/auth/logout" | Endpoint to call on logout |

<AuthGuard>

Protects routes by redirecting unauthenticated users.

import { AuthGuard } from "@auth-gate/react";

function ProtectedPage() {
  return (
    <AuthGuard redirectTo="/login" loadingFallback={<Spinner />}>
      <Dashboard />
    </AuthGuard>
  );
}

| Prop | Type | Default | Description | |------|------|---------|-------------| | redirectTo | string | "/login" | Redirect path when not authenticated | | loadingFallback | ReactNode | — | Shown while session is loading |

Hooks

useAuth()

Returns the full auth context.

const { user, loading, refresh, logout } = useAuth();

| Property | Type | Description | |----------|------|-------------| | user | AuthGateUser \| null | Current user or null | | loading | boolean | True while fetching session | | refresh | () => Promise<void> | Re-fetch the session | | logout | () => Promise<void> | Sign out and clear state |

useSession()

Shorthand that returns just the user.

const user = useSession(); // AuthGateUser | null

Authentication Examples

OAuth Sign-In

<a href="/api/auth/google/login">Sign in with Google</a>
<a href="/api/auth/github/login">Sign in with GitHub</a>

Email Sign-In

const res = await fetch("/api/auth/email/signin", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ email, password }),
});

const data = await res.json();

if (data.mfa_required) {
  await fetch("/api/auth/mfa/verify", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({
      mfa_challenge: data.mfa_challenge,
      code: totpCode,
      method: "totp",
    }),
  });
}

SMS Sign-In

await fetch("/api/auth/sms/send-code", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ phone: "+15551234567" }),
});

await fetch("/api/auth/sms/verify-code", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ phone: "+15551234567", code: "123456" }),
});

Server API Reference

createAuthRoutes(options)

Creates a Hono router with all auth endpoints.

| Option | Type | Required | Description | |--------|------|----------|-------------| | apiKey | string | Yes | AuthGate API key (also used to resolve project ID) | | baseUrl | string | Yes | AuthGate instance URL | | appUrl | string | Yes | Your app's URL | | cookieName | string | No | Cookie name (default: __authgate) | | sessionMaxAge | number | No | Session TTL in seconds (default: 604800) | | callbackPath | string | No | Callback path (default: /api/auth/callback) |

Types

import type { AuthGateUser, OAuthProvider } from "@auth-gate/react";

Re-exported from @auth-gate/core for convenience.

License

MIT