@authon/vue 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 ADDED
@@ -0,0 +1,47 @@
1
+ [English](./README.md) | **한국어**
2
+
3
+ # @authon/vue
4
+
5
+ > Vue 3 인증 -- composable, 컴포넌트 -- 셀프 호스팅 Clerk 대안
6
+
7
+ ## 설치
8
+
9
+ ```bash
10
+ npm install @authon/vue
11
+ ```
12
+
13
+ ## 빠른 시작
14
+
15
+ ```ts
16
+ // main.ts
17
+ import { createApp } from 'vue';
18
+ import { createAuthon } from '@authon/vue';
19
+ import App from './App.vue';
20
+
21
+ const app = createApp(App);
22
+ app.use(createAuthon({ publishableKey: 'pk_live_...', config: { apiUrl: 'https://your-authon-server.com' } }));
23
+ app.mount('#app');
24
+ ```
25
+
26
+ ```vue
27
+ <script setup lang="ts">
28
+ import { useAuthon, AuthonSignedIn, AuthonSignedOut, AuthonUserButton } from '@authon/vue';
29
+ const { openSignIn, signOut } = useAuthon();
30
+ </script>
31
+
32
+ <template>
33
+ <AuthonSignedOut><button @click="openSignIn()">로그인</button></AuthonSignedOut>
34
+ <AuthonSignedIn><AuthonUserButton /><button @click="signOut()">로그아웃</button></AuthonSignedIn>
35
+ </template>
36
+ ```
37
+
38
+ ## 환경 변수
39
+
40
+ | 변수 | 필수 | 설명 |
41
+ |------|------|------|
42
+ | `VITE_AUTHON_API_URL` | Yes | Authon 서버 URL |
43
+ | `VITE_AUTHON_PUBLISHABLE_KEY` | Yes | 퍼블리셔블 키 |
44
+
45
+ ## 라이선스
46
+
47
+ MIT
package/README.md CHANGED
@@ -1,125 +1,215 @@
1
+ **English** | [한국어](./README.ko.md)
2
+
1
3
  # @authon/vue
2
4
 
3
- Vue 3 SDK for [Authon](https://authon.dev)plugin, composables, and components.
5
+ > Drop-in Vue 3 authentication with composables and components self-hosted Clerk alternative, Auth0 alternative
6
+
7
+ [![npm version](https://img.shields.io/npm/v/@authon/vue?color=6d28d9)](https://www.npmjs.com/package/@authon/vue)
8
+ [![License](https://img.shields.io/badge/license-MIT-blue)](../../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/vue
9
- # or
10
- pnpm add @authon/vue
11
32
  ```
12
33
 
13
- Requires `vue >= 3.3.0`.
14
-
15
34
  ## Quick Start
16
35
 
17
- ### 1. Install the Plugin
18
-
19
36
  ```ts
20
- // main.ts
37
+ // src/main.ts
21
38
  import { createApp } from 'vue';
22
- import { AuthonPlugin } from '@authon/vue';
39
+ import { createAuthon } from '@authon/vue';
23
40
  import App from './App.vue';
24
41
 
25
42
  const app = createApp(App);
26
- app.use(AuthonPlugin, {
27
- publishableKey: 'pk_live_...',
28
- });
43
+ app.use(createAuthon({
44
+ publishableKey: 'pk_live_YOUR_PUBLISHABLE_KEY',
45
+ config: { apiUrl: 'https://your-authon-server.com' },
46
+ }));
29
47
  app.mount('#app');
30
48
  ```
31
49
 
32
- ### 2. Use Composables
50
+ ```vue
51
+ <!-- src/App.vue -->
52
+ <script setup lang="ts">
53
+ import { useAuthon, useUser, AuthonSignedIn, AuthonSignedOut, AuthonUserButton } from '@authon/vue';
54
+ const { openSignIn, signOut } = useAuthon();
55
+ const { user } = useUser();
56
+ </script>
57
+
58
+ <template>
59
+ <AuthonSignedOut>
60
+ <button @click="openSignIn()">Sign In</button>
61
+ </AuthonSignedOut>
62
+ <AuthonSignedIn>
63
+ <p>Welcome, {{ user?.email }}</p>
64
+ <AuthonUserButton />
65
+ <button @click="signOut()">Sign Out</button>
66
+ </AuthonSignedIn>
67
+ </template>
68
+ ```
69
+
70
+ ## Common Tasks
71
+
72
+ ### Add Google OAuth Login
33
73
 
34
74
  ```vue
35
75
  <script setup lang="ts">
36
- import { useAuthon, useUser } from '@authon/vue';
76
+ import { useAuthon } from '@authon/vue';
77
+ const { client } = useAuthon();
78
+ </script>
79
+
80
+ <template>
81
+ <button @click="client?.signInWithOAuth('google')">Sign in with Google</button>
82
+ </template>
83
+ ```
84
+
85
+ ### Protect a Route
86
+
87
+ ```ts
88
+ // src/router/index.ts
89
+ import { createRouter, createWebHistory } from 'vue-router';
90
+
91
+ const router = createRouter({
92
+ history: createWebHistory(),
93
+ routes: [
94
+ { path: '/', component: () => import('../views/Home.vue') },
95
+ { path: '/dashboard', component: () => import('../views/Dashboard.vue'), meta: { requiresAuth: true } },
96
+ { path: '/sign-in', component: () => import('../views/SignIn.vue') },
97
+ ],
98
+ });
99
+
100
+ router.beforeEach((to, _from, next) => {
101
+ if (to.meta.requiresAuth) {
102
+ const authon = router.app?.config.globalProperties.$authon;
103
+ if (!authon?.isSignedIn) return next({ path: '/sign-in', query: { redirect: to.fullPath } });
104
+ }
105
+ next();
106
+ });
37
107
 
38
- const { isSignedIn, openSignIn, signOut } = useAuthon();
108
+ export default router;
109
+ ```
110
+
111
+ ### Get Current User
112
+
113
+ ```vue
114
+ <script setup lang="ts">
115
+ import { useUser } from '@authon/vue';
39
116
  const { user, isLoading } = useUser();
40
117
  </script>
41
118
 
42
119
  <template>
43
- <div v-if="isLoading">Loading...</div>
44
- <div v-else-if="isSignedIn">
45
- <p>Welcome, {{ user?.displayName }}</p>
46
- <button @click="signOut()">Sign Out</button>
47
- </div>
48
- <div v-else>
49
- <button @click="openSignIn()">Sign In</button>
120
+ <p v-if="isLoading">Loading...</p>
121
+ <div v-else-if="user">
122
+ <p>Email: {{ user.email }}</p>
123
+ <p>Name: {{ user.displayName }}</p>
50
124
  </div>
125
+ <p v-else>Not signed in</p>
51
126
  </template>
52
127
  ```
53
128
 
54
- ### 3. Use Components
129
+ ### Add Email/Password Auth
55
130
 
56
131
  ```vue
132
+ <script setup lang="ts">
133
+ import { ref } from 'vue';
134
+ import { useAuthon } from '@authon/vue';
135
+ const { client } = useAuthon();
136
+ const email = ref('');
137
+ const password = ref('');
138
+
139
+ async function handleSignIn() {
140
+ await client?.signInWithEmail(email.value, password.value);
141
+ }
142
+ </script>
143
+
57
144
  <template>
58
- <SignedIn>
59
- <UserButton />
60
- </SignedIn>
61
- <SignedOut>
62
- <button @click="openSignIn()">Sign In</button>
63
- </SignedOut>
145
+ <form @submit.prevent="handleSignIn">
146
+ <input v-model="email" type="email" placeholder="Email" />
147
+ <input v-model="password" type="password" placeholder="Password" />
148
+ <button type="submit">Sign In</button>
149
+ </form>
64
150
  </template>
151
+ ```
65
152
 
66
- <script setup lang="ts">
67
- import { SignedIn, SignedOut, UserButton, useAuthon } from '@authon/vue';
153
+ ### Handle Sign Out
68
154
 
69
- const { openSignIn } = useAuthon();
155
+ ```vue
156
+ <script setup lang="ts">
157
+ import { useAuthon } from '@authon/vue';
158
+ const { signOut } = useAuthon();
70
159
  </script>
160
+
161
+ <template>
162
+ <button @click="signOut()">Sign Out</button>
163
+ </template>
71
164
  ```
72
165
 
166
+ ## Environment Variables
167
+
168
+ | Variable | Required | Description |
169
+ |----------|----------|-------------|
170
+ | `VITE_AUTHON_API_URL` | Yes | Your Authon server URL |
171
+ | `VITE_AUTHON_PUBLISHABLE_KEY` | Yes | Project publishable key |
172
+
73
173
  ## API Reference
74
174
 
75
175
  ### Plugin
76
176
 
77
177
  ```ts
78
- app.use(AuthonPlugin, {
79
- publishableKey: string;
80
- apiUrl?: string;
81
- theme?: 'light' | 'dark' | 'auto';
82
- locale?: string;
83
- appearance?: Partial<BrandingConfig>;
84
- });
178
+ createAuthon({ publishableKey: string, config?: AuthonConfig })
85
179
  ```
86
180
 
87
181
  ### Composables
88
182
 
89
- #### `useAuthon()`
90
-
91
- ```ts
92
- const {
93
- isSignedIn, // Ref<boolean>
94
- isLoading, // Ref<boolean>
95
- user, // Ref<AuthonUser | null>
96
- signOut, // () => Promise<void>
97
- openSignIn, // () => Promise<void>
98
- openSignUp, // () => Promise<void>
99
- getToken, // () => string | null
100
- client, // Authon instance
101
- } = useAuthon();
102
- ```
103
-
104
- #### `useUser()`
105
-
106
- ```ts
107
- const { user, isLoading } = useUser();
108
- ```
183
+ | Composable | Returns |
184
+ |------------|---------|
185
+ | `useAuthon()` | `{ isSignedIn, isLoading, user, client, signOut, openSignIn, openSignUp, getToken }` |
186
+ | `useUser()` | `{ user: ComputedRef, isLoading: ComputedRef }` |
187
+ | `useAuthonWeb3()` | Web3 wallet auth methods |
188
+ | `useAuthonPasswordless()` | Magic link and OTP methods |
189
+ | `useAuthonPasskeys()` | Passkey registration and auth |
109
190
 
110
191
  ### Components
111
192
 
112
193
  | Component | Description |
113
194
  |-----------|-------------|
114
- | `<SignedIn>` | Renders slot only when signed in |
115
- | `<SignedOut>` | Renders slot only when signed out |
116
- | `<UserButton>` | Avatar dropdown with sign-out |
117
- | `<Protect>` | Conditional rendering with fallback slot |
118
-
119
- ## Documentation
120
-
121
- [authon.dev/docs](https://authon.dev/docs)
195
+ | `<AuthonSignIn>` | Sign-in form (`mode="popup"` or `"embedded"`) |
196
+ | `<AuthonSignUp>` | Sign-up form |
197
+ | `<AuthonUserButton>` | Avatar dropdown with sign-out |
198
+ | `<AuthonSignedIn>` | Slot rendered only when signed in |
199
+ | `<AuthonSignedOut>` | Slot rendered only when signed out |
200
+ | `<AuthonSocialButtons>` | All enabled OAuth provider buttons |
201
+
202
+ ## Comparison
203
+
204
+ | Feature | Authon | Clerk | Auth.js |
205
+ |---------|--------|-------|---------|
206
+ | Self-hosted | Yes | No | Partial |
207
+ | Pricing | Free | $25/mo+ | Free |
208
+ | OAuth providers | 10+ | 20+ | 80+ |
209
+ | ShadowDOM modal | Yes | No | No |
210
+ | MFA/Passkeys | Yes | Yes | Plugin |
211
+ | Web3 auth | Yes | No | No |
122
212
 
123
213
  ## License
124
214
 
125
- [MIT](../../LICENSE)
215
+ MIT