@authon/react 0.2.1 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ko.md +95 -0
- package/README.md +173 -90
- package/dist/index.cjs +2009 -157
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +174 -9
- package/dist/index.d.ts +174 -9
- package/dist/index.js +1996 -157
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/README.ko.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
[English](./README.md) | **한국어**
|
|
2
|
+
|
|
3
|
+
# @authon/react
|
|
4
|
+
|
|
5
|
+
> React 인증 훅 및 컴포넌트 -- 셀프 호스팅 Clerk 대안, Auth0 대안
|
|
6
|
+
|
|
7
|
+
## 설치
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @authon/react
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## 빠른 시작
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import React from 'react';
|
|
17
|
+
import ReactDOM from 'react-dom/client';
|
|
18
|
+
import { AuthonProvider, useAuthon, useUser, SignedIn, SignedOut, UserButton } from '@authon/react';
|
|
19
|
+
|
|
20
|
+
function App() {
|
|
21
|
+
const { openSignIn, signOut } = useAuthon();
|
|
22
|
+
const { user } = useUser();
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<div>
|
|
26
|
+
<SignedOut>
|
|
27
|
+
<button onClick={() => openSignIn()}>로그인</button>
|
|
28
|
+
</SignedOut>
|
|
29
|
+
<SignedIn>
|
|
30
|
+
<p>환영합니다, {user?.email}</p>
|
|
31
|
+
<UserButton />
|
|
32
|
+
</SignedIn>
|
|
33
|
+
</div>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
ReactDOM.createRoot(document.getElementById('root')!).render(
|
|
38
|
+
<AuthonProvider publishableKey="pk_live_..." config={{ apiUrl: 'https://your-authon-server.com' }}>
|
|
39
|
+
<App />
|
|
40
|
+
</AuthonProvider>
|
|
41
|
+
);
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## 주요 작업
|
|
45
|
+
|
|
46
|
+
### Google OAuth 로그인
|
|
47
|
+
|
|
48
|
+
```tsx
|
|
49
|
+
const { client } = useAuthon();
|
|
50
|
+
<button onClick={() => client?.signInWithOAuth('google')}>Google로 로그인</button>
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### 라우트 보호
|
|
54
|
+
|
|
55
|
+
```tsx
|
|
56
|
+
import { Protect } from '@authon/react';
|
|
57
|
+
|
|
58
|
+
<Protect fallback={<p>로그인이 필요합니다.</p>}>
|
|
59
|
+
<Dashboard />
|
|
60
|
+
</Protect>
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### 현재 사용자
|
|
64
|
+
|
|
65
|
+
```tsx
|
|
66
|
+
const { user, isLoading } = useUser();
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### 로그아웃
|
|
70
|
+
|
|
71
|
+
```tsx
|
|
72
|
+
const { signOut } = useAuthon();
|
|
73
|
+
<button onClick={() => signOut()}>로그아웃</button>
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## 환경 변수
|
|
77
|
+
|
|
78
|
+
| 변수 | 필수 | 설명 |
|
|
79
|
+
|------|------|------|
|
|
80
|
+
| `AUTHON_API_URL` | Yes | Authon 서버 URL |
|
|
81
|
+
| `AUTHON_PUBLISHABLE_KEY` | Yes | 프로젝트 퍼블리셔블 키 |
|
|
82
|
+
|
|
83
|
+
## 비교
|
|
84
|
+
|
|
85
|
+
| 기능 | Authon | Clerk | Auth.js |
|
|
86
|
+
|------|--------|-------|---------|
|
|
87
|
+
| 셀프 호스팅 | Yes | No | 부분적 |
|
|
88
|
+
| 가격 | 무료 | $25/월+ | 무료 |
|
|
89
|
+
| ShadowDOM 모달 | Yes | No | No |
|
|
90
|
+
| MFA/패스키 | Yes | Yes | 플러그인 |
|
|
91
|
+
| Web3 인증 | Yes | No | No |
|
|
92
|
+
|
|
93
|
+
## 라이선스
|
|
94
|
+
|
|
95
|
+
MIT
|
package/README.md
CHANGED
|
@@ -1,137 +1,220 @@
|
|
|
1
|
+
**English** | [한국어](./README.ko.md)
|
|
2
|
+
|
|
1
3
|
# @authon/react
|
|
2
4
|
|
|
3
|
-
React
|
|
5
|
+
> Drop-in React authentication with hooks and components — self-hosted Clerk alternative, Auth0 alternative, open-source auth
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@authon/react)
|
|
8
|
+
[](../../LICENSE)
|
|
9
|
+
|
|
10
|
+
## Prerequisites
|
|
11
|
+
|
|
12
|
+
Before installing the SDK, create an Authon project and get your API keys:
|
|
13
|
+
|
|
14
|
+
1. **Create a project** at [Authon Dashboard](https://authon.dev/dashboard/overview)
|
|
15
|
+
- Click "Create Project" and enter your app name
|
|
16
|
+
- Select the authentication methods you want (Email/Password, OAuth providers, etc.)
|
|
17
|
+
|
|
18
|
+
2. **Get your API keys** from Project Settings → API Keys
|
|
19
|
+
- **Publishable Key** (`pk_live_...` or `pk_test_...`) — safe to use in client-side code
|
|
20
|
+
- **Secret Key** (`sk_live_...` or `sk_test_...`) — server-side only, never expose to clients
|
|
21
|
+
|
|
22
|
+
3. **Configure OAuth providers** (optional) in Project Settings → OAuth
|
|
23
|
+
- Add Google, Apple, GitHub, etc. with their respective Client ID and Secret
|
|
24
|
+
- Set the redirect URL to `https://api.authon.dev/v1/auth/oauth/redirect`
|
|
25
|
+
|
|
26
|
+
> **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.
|
|
4
27
|
|
|
5
28
|
## Install
|
|
6
29
|
|
|
7
30
|
```bash
|
|
8
31
|
npm install @authon/react
|
|
9
|
-
# or
|
|
10
|
-
pnpm add @authon/react
|
|
11
32
|
```
|
|
12
33
|
|
|
13
|
-
Requires `react >= 18.0.0`.
|
|
14
|
-
|
|
15
34
|
## Quick Start
|
|
16
35
|
|
|
17
36
|
```tsx
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
UserButton,
|
|
23
|
-
useUser,
|
|
24
|
-
useAuthon,
|
|
25
|
-
} from '@authon/react';
|
|
37
|
+
// src/main.tsx — complete working file
|
|
38
|
+
import React from 'react';
|
|
39
|
+
import ReactDOM from 'react-dom/client';
|
|
40
|
+
import { AuthonProvider, useAuthon, useUser, SignedIn, SignedOut, UserButton } from '@authon/react';
|
|
26
41
|
|
|
27
42
|
function App() {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
<Header />
|
|
31
|
-
<Main />
|
|
32
|
-
</AuthonProvider>
|
|
33
|
-
);
|
|
34
|
-
}
|
|
43
|
+
const { openSignIn, signOut } = useAuthon();
|
|
44
|
+
const { user } = useUser();
|
|
35
45
|
|
|
36
|
-
function Header() {
|
|
37
46
|
return (
|
|
38
|
-
<
|
|
47
|
+
<div>
|
|
48
|
+
<SignedOut>
|
|
49
|
+
<button onClick={() => openSignIn()}>Sign In</button>
|
|
50
|
+
</SignedOut>
|
|
39
51
|
<SignedIn>
|
|
52
|
+
<p>Welcome, {user?.email}</p>
|
|
40
53
|
<UserButton />
|
|
54
|
+
<button onClick={() => signOut()}>Sign Out</button>
|
|
41
55
|
</SignedIn>
|
|
42
|
-
|
|
43
|
-
<SignInButton />
|
|
44
|
-
</SignedOut>
|
|
45
|
-
</nav>
|
|
56
|
+
</div>
|
|
46
57
|
);
|
|
47
58
|
}
|
|
48
59
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
60
|
+
ReactDOM.createRoot(document.getElementById('root')!).render(
|
|
61
|
+
<AuthonProvider
|
|
62
|
+
publishableKey="pk_live_YOUR_PUBLISHABLE_KEY"
|
|
63
|
+
config={{ apiUrl: 'https://your-authon-server.com' }}
|
|
64
|
+
>
|
|
65
|
+
<App />
|
|
66
|
+
</AuthonProvider>
|
|
67
|
+
);
|
|
68
|
+
```
|
|
53
69
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
70
|
+
## Common Tasks
|
|
71
|
+
|
|
72
|
+
### Add Google OAuth Login
|
|
73
|
+
|
|
74
|
+
```tsx
|
|
75
|
+
import { useAuthon } from '@authon/react';
|
|
76
|
+
|
|
77
|
+
function GoogleLoginButton() {
|
|
78
|
+
const { client } = useAuthon();
|
|
79
|
+
return (
|
|
80
|
+
<button onClick={() => client?.signInWithOAuth('google')}>
|
|
81
|
+
Sign in with Google
|
|
82
|
+
</button>
|
|
83
|
+
);
|
|
59
84
|
}
|
|
60
85
|
```
|
|
61
86
|
|
|
62
|
-
|
|
87
|
+
### Protect a Route
|
|
88
|
+
|
|
89
|
+
```tsx
|
|
90
|
+
import { Protect } from '@authon/react';
|
|
91
|
+
|
|
92
|
+
function Dashboard() {
|
|
93
|
+
return (
|
|
94
|
+
<Protect fallback={<p>Please sign in to view this page.</p>}>
|
|
95
|
+
<h1>Dashboard</h1>
|
|
96
|
+
</Protect>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
63
99
|
|
|
64
|
-
|
|
100
|
+
// With role-based condition
|
|
101
|
+
function AdminPanel() {
|
|
102
|
+
return (
|
|
103
|
+
<Protect
|
|
104
|
+
condition={(user) => user.publicMetadata?.role === 'admin'}
|
|
105
|
+
fallback={<p>Admin access required.</p>}
|
|
106
|
+
>
|
|
107
|
+
<h1>Admin Panel</h1>
|
|
108
|
+
</Protect>
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
```
|
|
65
112
|
|
|
66
|
-
|
|
113
|
+
### Get Current User
|
|
67
114
|
|
|
68
115
|
```tsx
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
>
|
|
78
|
-
|
|
79
|
-
</
|
|
116
|
+
import { useUser } from '@authon/react';
|
|
117
|
+
|
|
118
|
+
function Profile() {
|
|
119
|
+
const { user, isLoading } = useUser();
|
|
120
|
+
if (isLoading) return <p>Loading...</p>;
|
|
121
|
+
if (!user) return <p>Not signed in</p>;
|
|
122
|
+
return (
|
|
123
|
+
<div>
|
|
124
|
+
<p>Email: {user.email}</p>
|
|
125
|
+
<p>Name: {user.displayName}</p>
|
|
126
|
+
</div>
|
|
127
|
+
);
|
|
128
|
+
}
|
|
80
129
|
```
|
|
81
130
|
|
|
82
|
-
###
|
|
131
|
+
### Add Email/Password Auth
|
|
132
|
+
|
|
133
|
+
```tsx
|
|
134
|
+
import { useAuthon } from '@authon/react';
|
|
135
|
+
import { useState } from 'react';
|
|
136
|
+
|
|
137
|
+
function EmailSignIn() {
|
|
138
|
+
const { client } = useAuthon();
|
|
139
|
+
const [email, setEmail] = useState('');
|
|
140
|
+
const [password, setPassword] = useState('');
|
|
83
141
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
client, // Authon instance
|
|
98
|
-
} = useAuthon();
|
|
142
|
+
const handleSubmit = async (e: React.FormEvent) => {
|
|
143
|
+
e.preventDefault();
|
|
144
|
+
await client?.signInWithEmail(email, password);
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
return (
|
|
148
|
+
<form onSubmit={handleSubmit}>
|
|
149
|
+
<input type="email" value={email} onChange={(e) => setEmail(e.target.value)} placeholder="Email" />
|
|
150
|
+
<input type="password" value={password} onChange={(e) => setPassword(e.target.value)} placeholder="Password" />
|
|
151
|
+
<button type="submit">Sign In</button>
|
|
152
|
+
</form>
|
|
153
|
+
);
|
|
154
|
+
}
|
|
99
155
|
```
|
|
100
156
|
|
|
101
|
-
|
|
157
|
+
### Handle Sign Out
|
|
102
158
|
|
|
103
|
-
|
|
159
|
+
```tsx
|
|
160
|
+
import { useAuthon } from '@authon/react';
|
|
104
161
|
|
|
105
|
-
|
|
106
|
-
const {
|
|
162
|
+
function SignOutButton() {
|
|
163
|
+
const { signOut } = useAuthon();
|
|
164
|
+
return <button onClick={() => signOut()}>Sign Out</button>;
|
|
165
|
+
}
|
|
107
166
|
```
|
|
108
167
|
|
|
109
|
-
|
|
168
|
+
## Environment Variables
|
|
110
169
|
|
|
111
|
-
|
|
|
112
|
-
|
|
113
|
-
|
|
|
114
|
-
|
|
|
115
|
-
| `<UserButton>` | none | Avatar dropdown with sign-out action |
|
|
116
|
-
| `<SignIn>` | `mode?` | Opens sign-in modal or renders embedded form |
|
|
117
|
-
| `<SignUp>` | `mode?` | Opens sign-up modal or renders embedded form |
|
|
118
|
-
| `<Protect>` | `fallback?`, `condition?` | Guards content, optionally with a custom condition |
|
|
170
|
+
| Variable | Required | Description |
|
|
171
|
+
|----------|----------|-------------|
|
|
172
|
+
| `AUTHON_API_URL` | Yes | Your Authon server URL |
|
|
173
|
+
| `AUTHON_PUBLISHABLE_KEY` | Yes | Project publishable key (`pk_live_...` or `pk_test_...`) |
|
|
119
174
|
|
|
120
|
-
|
|
175
|
+
## API Reference
|
|
121
176
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
177
|
+
### Components
|
|
178
|
+
|
|
179
|
+
| Component | Description |
|
|
180
|
+
|-----------|-------------|
|
|
181
|
+
| `<AuthonProvider>` | Context provider. Props: `publishableKey`, `config?` |
|
|
182
|
+
| `<SignIn>` | Pre-built sign-in form (`mode="popup"` or `"embedded"`) |
|
|
183
|
+
| `<SignUp>` | Pre-built sign-up form |
|
|
184
|
+
| `<UserButton>` | Avatar dropdown with user info and sign-out |
|
|
185
|
+
| `<UserProfile>` | Full user profile management |
|
|
186
|
+
| `<SignedIn>` | Renders children only when signed in |
|
|
187
|
+
| `<SignedOut>` | Renders children only when signed out |
|
|
188
|
+
| `<Protect>` | Conditional render with `fallback` and `condition` |
|
|
189
|
+
| `<SocialButton>` | Single OAuth provider button |
|
|
190
|
+
| `<SocialButtons>` | All enabled OAuth provider buttons |
|
|
130
191
|
|
|
131
|
-
|
|
192
|
+
### Hooks
|
|
132
193
|
|
|
133
|
-
|
|
194
|
+
| Hook | Returns |
|
|
195
|
+
|------|---------|
|
|
196
|
+
| `useAuthon()` | `{ isSignedIn, isLoading, user, signOut, openSignIn, openSignUp, getToken, client }` |
|
|
197
|
+
| `useUser()` | `{ user, isLoading }` |
|
|
198
|
+
| `useAuthonMfa()` | MFA setup, verification, and management |
|
|
199
|
+
| `useAuthonPasskeys()` | Passkey registration and authentication |
|
|
200
|
+
| `useAuthonPasswordless()` | Magic link and email OTP |
|
|
201
|
+
| `useAuthonWeb3()` | Web3 wallet sign-in and management |
|
|
202
|
+
| `useAuthonSessions()` | List and revoke active sessions |
|
|
203
|
+
| `useOrganization()` | Active organization management |
|
|
204
|
+
| `useOrganizationList()` | List and switch organizations |
|
|
205
|
+
|
|
206
|
+
## Comparison
|
|
207
|
+
|
|
208
|
+
| Feature | Authon | Clerk | Auth.js |
|
|
209
|
+
|---------|--------|-------|---------|
|
|
210
|
+
| Self-hosted | Yes | No | Partial |
|
|
211
|
+
| Pricing | Free | $25/mo+ | Free |
|
|
212
|
+
| OAuth providers | 10+ | 20+ | 80+ |
|
|
213
|
+
| ShadowDOM modal | Yes | No | No |
|
|
214
|
+
| MFA/Passkeys | Yes | Yes | Plugin |
|
|
215
|
+
| Web3 auth | Yes | No | No |
|
|
216
|
+
| Organizations | Yes | Yes | No |
|
|
134
217
|
|
|
135
218
|
## License
|
|
136
219
|
|
|
137
|
-
|
|
220
|
+
MIT
|