Sign In

@authon/react

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@authon/react

Authon React SDK — Provider, hooks, and components for React apps

latest
Source
npmnpm
Version
0.3.2
Version published
Maintainers
1
Created
Source

English | 한국어

@authon/react

Drop-in React authentication with hooks and components — Auth0 alternative, open-source auth

npm version License

Prerequisites

Before installing the SDK, create an Authon project and get your API keys:

  • Create a project at Authon Dashboard

    • Click "Create Project" and enter your app name
    • Select the authentication methods you want (Email/Password, OAuth providers, etc.)
  • Get your API keys from Project Settings → API Keys

    • Publishable Key (pk_live_...) — use in your frontend code
    • Test Key (pk_test_...) — for development, enables Dev Teleport
  • Configure OAuth providers (optional) in Project Settings → OAuth

    • Add Google, Apple, GitHub, etc. with their respective Client ID and Secret
    • Set the redirect URL to https://api.authon.dev/v1/auth/oauth/redirect

Test vs Live keys: Use pk_test_... during development. Switch to pk_live_... before deploying to production. Test keys use a sandbox environment with no rate limits.

Install

npm install @authon/react

Quick Start

// src/main.tsx — complete working file
import React from 'react';
import ReactDOM from 'react-dom/client';
import { AuthonProvider, useAuthon, useUser, SignedIn, SignedOut, UserButton } from '@authon/react';

function App() {
  const { openSignIn, signOut } = useAuthon();
  const { user } = useUser();

  return (
    <div>
      <SignedOut>
        <button onClick={() => openSignIn()}>Sign In</button>
      </SignedOut>
      <SignedIn>
        <p>Welcome, {user?.email}</p>
        <UserButton />
        <button onClick={() => signOut()}>Sign Out</button>
      </SignedIn>
    </div>
  );
}

ReactDOM.createRoot(document.getElementById('root')!).render(
  <AuthonProvider
    publishableKey="pk_live_YOUR_PUBLISHABLE_KEY"
  >
    <App />
  </AuthonProvider>
);

Common Tasks

Add Google OAuth Login

import { useAuthon } from '@authon/react';

function GoogleLoginButton() {
  const { client } = useAuthon();
  return (
    <button onClick={() => client?.signInWithOAuth('google')}>
      Sign in with Google
    </button>
  );
}

Protect a Route

import { Protect } from '@authon/react';

function Dashboard() {
  return (
    <Protect fallback={<p>Please sign in to view this page.</p>}>
      <h1>Dashboard</h1>
    </Protect>
  );
}

// With role-based condition
function AdminPanel() {
  return (
    <Protect
      condition={(user) => user.publicMetadata?.role === 'admin'}
      fallback={<p>Admin access required.</p>}
    >
      <h1>Admin Panel</h1>
    </Protect>
  );
}

Get Current User

import { useUser } from '@authon/react';

function Profile() {
  const { user, isLoading } = useUser();
  if (isLoading) return <p>Loading...</p>;
  if (!user) return <p>Not signed in</p>;
  return (
    <div>
      <p>Email: {user.email}</p>
      <p>Name: {user.displayName}</p>
    </div>
  );
}

Add Email/Password Auth

import { useAuthon } from '@authon/react';
import { useState } from 'react';

function EmailSignIn() {
  const { client } = useAuthon();
  const [email, setEmail] = useState('');
  const [password, setPassword] = useState('');

  const handleSubmit = async (e: React.FormEvent) => {
    e.preventDefault();
    await client?.signInWithEmail(email, password);
  };

  return (
    <form onSubmit={handleSubmit}>
      <input type="email" value={email} onChange={(e) => setEmail(e.target.value)} placeholder="Email" />
      <input type="password" value={password} onChange={(e) => setPassword(e.target.value)} placeholder="Password" />
      <button type="submit">Sign In</button>
    </form>
  );
}

Handle Sign Out

import { useAuthon } from '@authon/react';

function SignOutButton() {
  const { signOut } = useAuthon();
  return <button onClick={() => signOut()}>Sign Out</button>;
}

Environment Variables

VariableRequiredDescription
AUTHON_PUBLISHABLE_KEYYesProject publishable key (pk_live_... or pk_test_...)
AUTHON_API_URLNoOptional — defaults to api.authon.dev

API Reference

Components

ComponentDescription
<AuthonProvider>Context provider. Props: publishableKey, config?
<SignIn>Pre-built sign-in form (mode="popup" or "embedded")
<SignUp>Pre-built sign-up form
<UserButton>Avatar dropdown with user info and sign-out
<UserProfile>Full user profile management
<SignedIn>Renders children only when signed in
<SignedOut>Renders children only when signed out
<Protect>Conditional render with fallback and condition
<SocialButton>Single OAuth provider button
<SocialButtons>All enabled OAuth provider buttons

Hooks

HookReturns
useAuthon(){ isSignedIn, isLoading, user, signOut, openSignIn, openSignUp, getToken, client }
useUser(){ user, isLoading }
useAuthonMfa()MFA setup, verification, and management
useAuthonPasskeys()Passkey registration and authentication
useAuthonPasswordless()Magic link and email OTP
useAuthonWeb3()Web3 wallet sign-in and management
useAuthonSessions()List and revoke active sessions
useOrganization()Active organization management
useOrganizationList()List and switch organizations

Comparison

FeatureAuthonClerkAuth.js
PricingFree$25/mo+Free
OAuth providers10+20+80+
ShadowDOM modalYesNoNo
MFA/PasskeysYesYesPlugin
Web3 authYesNoNo
OrganizationsYesYesNo

License

MIT

Keywords

authon

FAQs

Package last updated on 31 Mar 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts