@authon/vue 0.3.0 → 0.3.2
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 +13 -136
- package/README.md +136 -391
- package/dist/index.cjs +72 -33
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +44 -19
- package/dist/index.d.ts +44 -19
- package/dist/index.js +71 -32
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.ko.md
CHANGED
|
@@ -2,169 +2,46 @@
|
|
|
2
2
|
|
|
3
3
|
# @authon/vue
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
> Vue 3 인증 -- composable, 컴포넌트 -- 셀프 호스팅 Clerk 대안
|
|
6
6
|
|
|
7
7
|
## 설치
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
10
|
npm install @authon/vue
|
|
11
|
-
# 또는
|
|
12
|
-
pnpm add @authon/vue
|
|
13
11
|
```
|
|
14
12
|
|
|
15
|
-
`vue >= 3.3.0`이 필요합니다.
|
|
16
|
-
|
|
17
13
|
## 빠른 시작
|
|
18
14
|
|
|
19
|
-
### 1. 플러그인 설치
|
|
20
|
-
|
|
21
15
|
```ts
|
|
22
16
|
// main.ts
|
|
23
17
|
import { createApp } from 'vue';
|
|
24
|
-
import {
|
|
18
|
+
import { createAuthon } from '@authon/vue';
|
|
25
19
|
import App from './App.vue';
|
|
26
20
|
|
|
27
21
|
const app = createApp(App);
|
|
28
|
-
app.use(
|
|
29
|
-
publishableKey: 'pk_live_...',
|
|
30
|
-
});
|
|
22
|
+
app.use(createAuthon({ publishableKey: 'pk_live_...', config: { apiUrl: 'https://your-authon-server.com' } }));
|
|
31
23
|
app.mount('#app');
|
|
32
24
|
```
|
|
33
25
|
|
|
34
|
-
### 2. Composable 사용
|
|
35
|
-
|
|
36
26
|
```vue
|
|
37
27
|
<script setup lang="ts">
|
|
38
|
-
import { useAuthon,
|
|
39
|
-
|
|
40
|
-
const { isSignedIn, openSignIn, signOut } = useAuthon();
|
|
41
|
-
const { user, isLoading } = useUser();
|
|
28
|
+
import { useAuthon, AuthonSignedIn, AuthonSignedOut, AuthonUserButton } from '@authon/vue';
|
|
29
|
+
const { openSignIn, signOut } = useAuthon();
|
|
42
30
|
</script>
|
|
43
31
|
|
|
44
32
|
<template>
|
|
45
|
-
<
|
|
46
|
-
<
|
|
47
|
-
<p>Welcome, {{ user?.displayName }}</p>
|
|
48
|
-
<button @click="signOut()">Sign Out</button>
|
|
49
|
-
</div>
|
|
50
|
-
<div v-else>
|
|
51
|
-
<button @click="openSignIn()">Sign In</button>
|
|
52
|
-
</div>
|
|
33
|
+
<AuthonSignedOut><button @click="openSignIn()">로그인</button></AuthonSignedOut>
|
|
34
|
+
<AuthonSignedIn><AuthonUserButton /><button @click="signOut()">로그아웃</button></AuthonSignedIn>
|
|
53
35
|
</template>
|
|
54
36
|
```
|
|
55
37
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
```vue
|
|
59
|
-
<template>
|
|
60
|
-
<SignedIn>
|
|
61
|
-
<UserButton />
|
|
62
|
-
</SignedIn>
|
|
63
|
-
<SignedOut>
|
|
64
|
-
<button @click="openSignIn()">Sign In</button>
|
|
65
|
-
</SignedOut>
|
|
66
|
-
</template>
|
|
67
|
-
|
|
68
|
-
<script setup lang="ts">
|
|
69
|
-
import { SignedIn, SignedOut, UserButton, useAuthon } from '@authon/vue';
|
|
70
|
-
|
|
71
|
-
const { openSignIn } = useAuthon();
|
|
72
|
-
</script>
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
## API 레퍼런스
|
|
76
|
-
|
|
77
|
-
### 플러그인
|
|
78
|
-
|
|
79
|
-
```ts
|
|
80
|
-
app.use(AuthonPlugin, {
|
|
81
|
-
publishableKey: string;
|
|
82
|
-
apiUrl?: string;
|
|
83
|
-
theme?: 'light' | 'dark' | 'auto';
|
|
84
|
-
locale?: string;
|
|
85
|
-
appearance?: Partial<BrandingConfig>;
|
|
86
|
-
});
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
### Composable
|
|
90
|
-
|
|
91
|
-
#### `useAuthon()`
|
|
92
|
-
|
|
93
|
-
```ts
|
|
94
|
-
const {
|
|
95
|
-
isSignedIn, // Ref<boolean>
|
|
96
|
-
isLoading, // Ref<boolean>
|
|
97
|
-
user, // Ref<AuthonUser | null>
|
|
98
|
-
signOut, // () => Promise<void>
|
|
99
|
-
openSignIn, // () => Promise<void>
|
|
100
|
-
openSignUp, // () => Promise<void>
|
|
101
|
-
getToken, // () => string | null
|
|
102
|
-
client, // Authon 인스턴스
|
|
103
|
-
} = useAuthon();
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
#### `useUser()`
|
|
107
|
-
|
|
108
|
-
```ts
|
|
109
|
-
const { user, isLoading } = useUser();
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
### 컴포넌트
|
|
113
|
-
|
|
114
|
-
| 컴포넌트 | 설명 |
|
|
115
|
-
|----------|------|
|
|
116
|
-
| `<SignedIn>` | 로그인 상태일 때만 슬롯을 렌더링 |
|
|
117
|
-
| `<SignedOut>` | 로그아웃 상태일 때만 슬롯을 렌더링 |
|
|
118
|
-
| `<UserButton>` | 로그아웃 기능이 포함된 아바타 드롭다운 |
|
|
119
|
-
| `<Protect>` | fallback 슬롯을 지원하는 조건부 렌더링 |
|
|
120
|
-
|
|
121
|
-
## Multi-Factor Authentication (MFA)
|
|
122
|
-
|
|
123
|
-
`useAuthon()`의 `client` 인스턴스를 통해 MFA 메서드에 접근합니다.
|
|
124
|
-
|
|
125
|
-
```vue
|
|
126
|
-
<script setup lang="ts">
|
|
127
|
-
import { ref } from 'vue';
|
|
128
|
-
import { useAuthon } from '@authon/vue';
|
|
129
|
-
import { AuthonMfaRequiredError } from '@authon/js';
|
|
130
|
-
|
|
131
|
-
const { client } = useAuthon();
|
|
132
|
-
const qrSvg = ref('');
|
|
133
|
-
const mfaToken = ref('');
|
|
134
|
-
|
|
135
|
-
// MFA 설정
|
|
136
|
-
async function enableMfa() {
|
|
137
|
-
const setup = await client.value!.setupMfa();
|
|
138
|
-
qrSvg.value = setup.qrCodeSvg; // 인증 앱에 표시할 QR 코드
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
async function verifySetup(code: string) {
|
|
142
|
-
await client.value!.verifyMfaSetup(code);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// MFA를 사용한 로그인
|
|
146
|
-
async function signIn(email: string, password: string) {
|
|
147
|
-
try {
|
|
148
|
-
await client.value!.signInWithEmail(email, password);
|
|
149
|
-
} catch (err) {
|
|
150
|
-
if (err instanceof AuthonMfaRequiredError) {
|
|
151
|
-
mfaToken.value = err.mfaToken; // TOTP 입력 화면 표시
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
async function verifyMfa(code: string) {
|
|
157
|
-
await client.value!.verifyMfa(mfaToken.value, code);
|
|
158
|
-
}
|
|
159
|
-
</script>
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
전체 API 레퍼런스는 [`@authon/js` MFA 문서](../js/README.md#multi-factor-authentication-mfa)를 참고하세요.
|
|
163
|
-
|
|
164
|
-
## 문서
|
|
38
|
+
## 환경 변수
|
|
165
39
|
|
|
166
|
-
|
|
40
|
+
| 변수 | 필수 | 설명 |
|
|
41
|
+
|------|------|------|
|
|
42
|
+
| `VITE_AUTHON_API_URL` | Yes | Authon 서버 URL |
|
|
43
|
+
| `VITE_AUTHON_PUBLISHABLE_KEY` | Yes | 퍼블리셔블 키 |
|
|
167
44
|
|
|
168
45
|
## 라이선스
|
|
169
46
|
|
|
170
|
-
|
|
47
|
+
MIT
|