@kood/claude-code 0.2.5 → 0.3.0
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/dist/index.js +13 -8
- package/package.json +1 -1
- package/templates/.claude/agents/code-reviewer.md +371 -19
- package/templates/.claude/agents/dependency-manager.md +197 -0
- package/templates/.claude/agents/deployment-validator.md +136 -0
- package/templates/.claude/agents/git-operator.md +147 -0
- package/templates/.claude/agents/implementation-executor.md +202 -0
- package/templates/.claude/agents/lint-fixer.md +155 -0
- package/templates/.claude/agents/refactor-advisor.md +339 -29
- package/templates/.claude/commands/agent-creator.md +355 -0
- package/templates/.claude/commands/docs-creator.md +404 -163
- package/templates/.claude/commands/docs-refactor.md +400 -113
- package/templates/.claude/commands/execute.md +357 -185
- package/templates/.claude/commands/git-all.md +16 -70
- package/templates/.claude/commands/git-session.md +36 -68
- package/templates/.claude/commands/git.md +20 -69
- package/templates/.claude/commands/lint-fix.md +164 -107
- package/templates/.claude/commands/lint-init.md +142 -168
- package/templates/.claude/commands/plan.md +300 -84
- package/templates/.claude/commands/prd.md +497 -214
- package/templates/.claude/commands/pre-deploy.md +242 -0
- package/templates/.claude/commands/subagent-creator.md +118 -0
- package/templates/.claude/commands/version-update.md +45 -57
- package/templates/hono/CLAUDE.md +99 -54
- package/templates/hono/docs/guides/conventions.md +352 -0
- package/templates/hono/docs/guides/env-setup.md +347 -0
- package/templates/hono/docs/guides/getting-started.md +239 -0
- package/templates/hono/docs/library/hono/error-handling.md +20 -29
- package/templates/hono/docs/library/hono/index.md +25 -52
- package/templates/hono/docs/library/hono/middleware.md +16 -75
- package/templates/hono/docs/library/hono/rpc.md +7 -35
- package/templates/hono/docs/library/hono/validation.md +25 -45
- package/templates/hono/docs/library/t3-env/index.md +374 -0
- package/templates/npx/CLAUDE.md +165 -65
- package/templates/npx/docs/library/commander/index.md +10 -73
- package/templates/npx/docs/library/fs-extra/index.md +21 -113
- package/templates/npx/docs/library/prompts/index.md +30 -176
- package/templates/npx/docs/references/patterns.md +75 -48
- package/templates/tanstack-start/CLAUDE.md +101 -77
- package/templates/tanstack-start/docs/architecture.md +427 -0
- package/templates/tanstack-start/docs/design.md +558 -0
- package/templates/tanstack-start/docs/guides/conventions.md +132 -32
- package/templates/tanstack-start/docs/guides/env-setup.md +127 -62
- package/templates/tanstack-start/docs/guides/getting-started.md +81 -20
- package/templates/tanstack-start/docs/guides/hooks.md +241 -36
- package/templates/tanstack-start/docs/guides/routes.md +213 -61
- package/templates/tanstack-start/docs/guides/services.md +260 -24
- package/templates/tanstack-start/docs/library/better-auth/index.md +469 -16
- package/templates/tanstack-start/docs/library/t3-env/index.md +307 -0
- package/templates/tanstack-start/docs/library/tanstack-query/index.md +12 -21
- package/templates/tanstack-start/docs/library/tanstack-query/invalidation.md +22 -35
- package/templates/tanstack-start/docs/library/tanstack-query/optimistic-updates.md +7 -24
- package/templates/tanstack-start/docs/library/tanstack-query/use-mutation.md +26 -39
- package/templates/tanstack-start/docs/library/tanstack-query/use-query.md +23 -26
- package/templates/tanstack-start/docs/library/tanstack-router/error-handling.md +32 -147
- package/templates/tanstack-start/docs/library/tanstack-router/hooks.md +25 -167
- package/templates/tanstack-start/docs/library/tanstack-router/index.md +39 -74
- package/templates/tanstack-start/docs/library/tanstack-router/navigation.md +46 -116
- package/templates/tanstack-start/docs/library/tanstack-router/route-context.md +35 -154
- package/templates/tanstack-start/docs/library/tanstack-router/search-params.md +32 -171
- package/templates/tanstack-start/docs/library/tanstack-start/auth-patterns.md +7 -15
- package/templates/tanstack-start/docs/library/tanstack-start/routing.md +16 -23
- package/templates/tanstack-start/docs/library/zod/complex-types.md +12 -31
- package/templates/tanstack-start/docs/library/zod/index.md +18 -35
- package/templates/tanstack-start/docs/library/zod/transforms.md +11 -25
- package/templates/tanstack-start/docs/library/zod/validation.md +12 -34
- package/templates/.claude/agents/debug-detective.md +0 -37
- package/templates/.claude/agents/test-writer.md +0 -41
- package/templates/.claude/commands/feedback.md +0 -199
- package/templates/.claude/commands/ts-fix.md +0 -176
- package/templates/.claude/skills/command-creator/LICENSE.txt +0 -202
- package/templates/.claude/skills/command-creator/SKILL.md +0 -245
- package/templates/.claude/skills/command-creator/scripts/init_command.py +0 -244
- package/templates/.claude/skills/command-creator/scripts/package_command.py +0 -125
- package/templates/.claude/skills/command-creator/scripts/quick_validate.py +0 -143
- package/templates/.claude/skills/frontend-design/SKILL.md +0 -310
- package/templates/.claude/skills/frontend-design/references/animation-patterns.md +0 -446
- package/templates/.claude/skills/frontend-design/references/colors-2026.md +0 -244
- package/templates/.claude/skills/frontend-design/references/typography-2026.md +0 -302
- package/templates/.claude/skills/gemini-review/SKILL.md +0 -118
- package/templates/.claude/skills/gemini-review/references/checklists.md +0 -129
- package/templates/.claude/skills/gemini-review/references/prompt-templates.md +0 -274
- package/templates/.claude/skills/skill-creator/LICENSE.txt +0 -202
- package/templates/.claude/skills/skill-creator/SKILL.md +0 -184
- package/templates/.claude/skills/skill-creator/scripts/init_skill.py +0 -303
- package/templates/.claude/skills/skill-creator/scripts/package_skill.py +0 -110
- package/templates/.claude/skills/skill-creator/scripts/quick_validate.py +0 -65
- package/templates/hono/docs/library/ai-sdk/index.md +0 -190
- package/templates/hono/docs/library/ai-sdk/openrouter.md +0 -111
- package/templates/hono/docs/library/ai-sdk/providers.md +0 -102
- package/templates/hono/docs/library/ai-sdk/streaming.md +0 -146
- package/templates/hono/docs/library/ai-sdk/structured-output.md +0 -161
- package/templates/hono/docs/library/ai-sdk/tools.md +0 -144
- package/templates/hono/docs/library/drizzle/cloudflare-d1.md +0 -247
- package/templates/hono/docs/library/drizzle/config.md +0 -167
- package/templates/hono/docs/library/drizzle/index.md +0 -259
- package/templates/hono/docs/library/hono/env-setup.md +0 -169
- package/templates/hono/docs/library/pino/index.md +0 -146
- package/templates/tanstack-start/docs/architecture/architecture.md +0 -243
- package/templates/tanstack-start/docs/deployment/cloudflare.md +0 -132
- package/templates/tanstack-start/docs/deployment/index.md +0 -163
- package/templates/tanstack-start/docs/deployment/nitro.md +0 -110
- package/templates/tanstack-start/docs/deployment/railway.md +0 -147
- package/templates/tanstack-start/docs/deployment/vercel.md +0 -135
- package/templates/tanstack-start/docs/design/components.md +0 -175
- package/templates/tanstack-start/docs/design/index.md +0 -151
- package/templates/tanstack-start/docs/design/safe-area.md +0 -118
- package/templates/tanstack-start/docs/design/tailwind-setup.md +0 -156
- package/templates/tanstack-start/docs/library/ai-sdk/hooks.md +0 -472
- package/templates/tanstack-start/docs/library/ai-sdk/index.md +0 -264
- package/templates/tanstack-start/docs/library/ai-sdk/openrouter.md +0 -371
- package/templates/tanstack-start/docs/library/ai-sdk/providers.md +0 -403
- package/templates/tanstack-start/docs/library/ai-sdk/streaming.md +0 -320
- package/templates/tanstack-start/docs/library/ai-sdk/structured-output.md +0 -454
- package/templates/tanstack-start/docs/library/ai-sdk/tools.md +0 -473
- package/templates/tanstack-start/docs/library/better-auth/2fa.md +0 -48
- package/templates/tanstack-start/docs/library/better-auth/advanced.md +0 -55
- package/templates/tanstack-start/docs/library/better-auth/plugins.md +0 -34
- package/templates/tanstack-start/docs/library/better-auth/session.md +0 -47
- package/templates/tanstack-start/docs/library/better-auth/setup.md +0 -41
- package/templates/tanstack-start/docs/library/drizzle/cloudflare-d1.md +0 -147
- package/templates/tanstack-start/docs/library/drizzle/config.md +0 -118
- package/templates/tanstack-start/docs/library/drizzle/crud.md +0 -205
- package/templates/tanstack-start/docs/library/drizzle/index.md +0 -79
- package/templates/tanstack-start/docs/library/drizzle/relations.md +0 -202
- package/templates/tanstack-start/docs/library/drizzle/schema.md +0 -154
- package/templates/tanstack-start/docs/library/drizzle/setup.md +0 -96
- package/templates/tanstack-start/docs/library/drizzle/transactions.md +0 -127
- package/templates/tanstack-start/docs/library/pino/index.md +0 -320
- /package/templates/hono/docs/{architecture/architecture.md → architecture.md} +0 -0
|
@@ -2,33 +2,486 @@
|
|
|
2
2
|
|
|
3
3
|
> TypeScript Authentication Library
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
@session.md
|
|
7
|
-
@plugins.md
|
|
8
|
-
@2fa.md
|
|
9
|
-
@advanced.md
|
|
5
|
+
---
|
|
10
6
|
|
|
11
|
-
|
|
7
|
+
<quick_start>
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install better-auth
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Minimal Setup
|
|
12
16
|
|
|
13
17
|
```typescript
|
|
14
|
-
// 서버
|
|
18
|
+
// src/lib/auth.ts - 서버
|
|
15
19
|
import { betterAuth } from 'better-auth'
|
|
16
20
|
import { prismaAdapter } from 'better-auth/adapters/prisma'
|
|
21
|
+
import { prisma } from '@/database/prisma'
|
|
17
22
|
|
|
18
23
|
export const auth = betterAuth({
|
|
19
|
-
database: prismaAdapter(prisma),
|
|
24
|
+
database: prismaAdapter(prisma, { provider: 'postgresql' }),
|
|
20
25
|
emailAndPassword: { enabled: true },
|
|
21
26
|
})
|
|
22
27
|
|
|
23
|
-
// 클라이언트
|
|
28
|
+
// src/lib/auth-client.ts - 클라이언트
|
|
24
29
|
import { createAuthClient } from 'better-auth/react'
|
|
25
|
-
export const authClient = createAuthClient({})
|
|
26
30
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
export const authClient = createAuthClient({
|
|
32
|
+
baseURL: 'http://localhost:3000',
|
|
33
|
+
})
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## TanStack Start Handler
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
// src/routes/api/auth/$.ts
|
|
40
|
+
import { auth } from '@/lib/auth'
|
|
41
|
+
|
|
42
|
+
export const GET = async ({ request }: { request: Request }) => auth.handler(request)
|
|
43
|
+
export const POST = async ({ request }: { request: Request }) => auth.handler(request)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
</quick_start>
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
<setup>
|
|
51
|
+
|
|
52
|
+
## Database Adapters
|
|
53
|
+
|
|
54
|
+
| Adapter | Import | Provider |
|
|
55
|
+
|---------|--------|----------|
|
|
56
|
+
| Prisma | `better-auth/adapters/prisma` | `postgresql`, `mysql`, `sqlite` |
|
|
57
|
+
| Drizzle | `better-auth/adapters/drizzle` | `pg`, `mysql2`, `better-sqlite3` |
|
|
58
|
+
| Kysely | `better-auth/adapters/kysely` | dialect 기반 |
|
|
59
|
+
|
|
60
|
+
## Auth Config
|
|
61
|
+
|
|
62
|
+
| 옵션 | 타입 | 기본값 | 설명 |
|
|
63
|
+
|------|------|--------|------|
|
|
64
|
+
| `database` | `Adapter` | 필수 | DB 어댑터 |
|
|
65
|
+
| `baseURL` | `string` | `http://localhost:3000` | 앱 URL |
|
|
66
|
+
| `basePath` | `string` | `/api/auth` | Auth 경로 |
|
|
67
|
+
| `secret` | `string` | 환경변수 | JWT 시크릿 |
|
|
68
|
+
| `trustedOrigins` | `string[]` | `[]` | CORS 허용 오리진 |
|
|
69
|
+
|
|
70
|
+
## Social Providers
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
export const auth = betterAuth({
|
|
74
|
+
database: prismaAdapter(prisma),
|
|
75
|
+
socialProviders: {
|
|
76
|
+
google: {
|
|
77
|
+
clientId: process.env.GOOGLE_CLIENT_ID!,
|
|
78
|
+
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
|
|
79
|
+
},
|
|
80
|
+
github: {
|
|
81
|
+
clientId: process.env.GITHUB_CLIENT_ID!,
|
|
82
|
+
clientSecret: process.env.GITHUB_CLIENT_SECRET!,
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
})
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Email & Password
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
export const auth = betterAuth({
|
|
92
|
+
emailAndPassword: {
|
|
93
|
+
enabled: true,
|
|
94
|
+
requireEmailVerification: false,
|
|
95
|
+
sendResetPassword: async ({ user, url }) => {
|
|
96
|
+
await sendEmail({ to: user.email, subject: 'Reset Password', html: `<a href="${url}">Reset</a>` })
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
})
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
</setup>
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
<session>
|
|
107
|
+
|
|
108
|
+
## Session Config
|
|
109
|
+
|
|
110
|
+
| 옵션 | 타입 | 기본값 | 설명 |
|
|
111
|
+
|------|------|--------|------|
|
|
112
|
+
| `expiresIn` | `number` | `604800` (7일) | 세션 만료 시간 (초) |
|
|
113
|
+
| `updateAge` | `number` | `86400` (1일) | 세션 갱신 주기 (초) |
|
|
114
|
+
| `cookieCache.enabled` | `boolean` | `true` | 쿠키 캐시 활성화 |
|
|
115
|
+
| `cookieCache.maxAge` | `number` | `300` (5분) | 캐시 유효 시간 (초) |
|
|
116
|
+
| `cookieCache.strategy` | `'compact' \| 'jwt' \| 'jwe'` | `'compact'` | 캐시 전략 |
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
export const auth = betterAuth({
|
|
120
|
+
session: {
|
|
121
|
+
expiresIn: 604800, // 7일
|
|
122
|
+
updateAge: 86400, // 1일마다 갱신
|
|
123
|
+
cookieCache: {
|
|
124
|
+
enabled: true,
|
|
125
|
+
maxAge: 300, // 5분
|
|
126
|
+
strategy: 'compact',
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
})
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Session Methods
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
// ✅ 클라이언트
|
|
136
|
+
const session = await authClient.getSession()
|
|
137
|
+
const session = await authClient.getSession({ query: { disableCookieCache: true } })
|
|
138
|
+
|
|
139
|
+
// ✅ 서버 (TanStack Start)
|
|
140
|
+
export const getSession = createServerFn({ method: 'GET' })
|
|
141
|
+
.handler(async ({ request }) => {
|
|
142
|
+
const session = await auth.api.getSession({ headers: request.headers })
|
|
143
|
+
return session
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
// ✅ 세션 업데이트
|
|
147
|
+
await authClient.updateUser({ name: 'New Name' })
|
|
30
148
|
|
|
31
|
-
//
|
|
32
|
-
|
|
33
|
-
const session = await auth.api.getSession({ headers }) // 서버
|
|
149
|
+
// ✅ 로그아웃
|
|
150
|
+
await authClient.signOut()
|
|
34
151
|
```
|
|
152
|
+
|
|
153
|
+
## Custom Session Fields
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
import { customSession } from 'better-auth/plugins'
|
|
157
|
+
|
|
158
|
+
export const auth = betterAuth({
|
|
159
|
+
plugins: [
|
|
160
|
+
customSession({
|
|
161
|
+
schema: {
|
|
162
|
+
session: {
|
|
163
|
+
fields: {
|
|
164
|
+
ipAddress: { type: 'string' },
|
|
165
|
+
userAgent: { type: 'string' },
|
|
166
|
+
metadata: { type: 'json' },
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
async onSessionCreate(session, context) {
|
|
171
|
+
return {
|
|
172
|
+
...session,
|
|
173
|
+
ipAddress: context.request.headers.get('x-forwarded-for') || 'unknown',
|
|
174
|
+
userAgent: context.request.headers.get('user-agent') || 'unknown',
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
}),
|
|
178
|
+
],
|
|
179
|
+
})
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
</session>
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
<auth_methods>
|
|
187
|
+
|
|
188
|
+
## Email/Password
|
|
189
|
+
|
|
190
|
+
```typescript
|
|
191
|
+
// ✅ 회원가입
|
|
192
|
+
await authClient.signUp.email({
|
|
193
|
+
email: 'user@example.com',
|
|
194
|
+
password: 'password123',
|
|
195
|
+
name: 'User Name',
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
// ✅ 로그인
|
|
199
|
+
await authClient.signIn.email({
|
|
200
|
+
email: 'user@example.com',
|
|
201
|
+
password: 'password123',
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
// ✅ 비밀번호 재설정 요청
|
|
205
|
+
await authClient.forgetPassword({ email: 'user@example.com' })
|
|
206
|
+
|
|
207
|
+
// ✅ 비밀번호 재설정
|
|
208
|
+
await authClient.resetPassword({ token, password: 'newpassword' })
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## Social Login
|
|
212
|
+
|
|
213
|
+
```typescript
|
|
214
|
+
// ✅ 소셜 로그인
|
|
215
|
+
await authClient.signIn.social({ provider: 'google', callbackURL: '/dashboard' })
|
|
216
|
+
await authClient.signIn.social({ provider: 'github', callbackURL: '/dashboard' })
|
|
217
|
+
|
|
218
|
+
// ✅ SSO
|
|
219
|
+
await authClient.signIn.sso({ providerId: 'provider-id', callbackURL: '/dashboard' })
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
## Two-Factor Authentication
|
|
223
|
+
|
|
224
|
+
### Server Setup
|
|
225
|
+
|
|
226
|
+
```typescript
|
|
227
|
+
import { twoFactor } from 'better-auth/plugins'
|
|
228
|
+
|
|
229
|
+
export const auth = betterAuth({
|
|
230
|
+
plugins: [
|
|
231
|
+
twoFactor({
|
|
232
|
+
issuer: 'My App',
|
|
233
|
+
otpOptions: {
|
|
234
|
+
async sendOTP({ user, otp }) {
|
|
235
|
+
await sendEmail({
|
|
236
|
+
to: user.email,
|
|
237
|
+
subject: 'Your OTP Code',
|
|
238
|
+
html: `Your code: ${otp}`,
|
|
239
|
+
})
|
|
240
|
+
},
|
|
241
|
+
period: 300, // 5분
|
|
242
|
+
length: 6, // 6자리
|
|
243
|
+
},
|
|
244
|
+
backupCodeLength: 10,
|
|
245
|
+
backupCodeCount: 10,
|
|
246
|
+
}),
|
|
247
|
+
],
|
|
248
|
+
})
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
### Client Setup
|
|
252
|
+
|
|
253
|
+
```typescript
|
|
254
|
+
import { twoFactorClient } from 'better-auth/client/plugins'
|
|
255
|
+
|
|
256
|
+
export const authClient = createAuthClient({
|
|
257
|
+
plugins: [
|
|
258
|
+
twoFactorClient({
|
|
259
|
+
twoFactorPage: '/two-factor',
|
|
260
|
+
}),
|
|
261
|
+
],
|
|
262
|
+
})
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### 2FA Usage
|
|
266
|
+
|
|
267
|
+
```typescript
|
|
268
|
+
// ✅ TOTP 활성화
|
|
269
|
+
const { data } = await authClient.twoFactor.enable({ password: 'current-password' })
|
|
270
|
+
// data: { totpURI: 'otpauth://...', backupCodes: ['ABCD-1234', ...] }
|
|
271
|
+
|
|
272
|
+
// ✅ TOTP 검증
|
|
273
|
+
await authClient.twoFactor.verifyTotp({ code: '123456' })
|
|
274
|
+
|
|
275
|
+
// ✅ OTP 전송
|
|
276
|
+
await authClient.twoFactor.sendOtp()
|
|
277
|
+
|
|
278
|
+
// ✅ OTP 검증
|
|
279
|
+
await authClient.twoFactor.verifyOtp({ code: '123456' })
|
|
280
|
+
|
|
281
|
+
// ✅ 백업 코드 사용
|
|
282
|
+
await authClient.twoFactor.useBackupCode({ code: 'ABCD-1234' })
|
|
283
|
+
|
|
284
|
+
// ✅ 백업 코드 재생성
|
|
285
|
+
const { data } = await authClient.twoFactor.regenerateBackupCodes({ password: 'current-password' })
|
|
286
|
+
|
|
287
|
+
// ✅ 2FA 비활성화
|
|
288
|
+
await authClient.twoFactor.disable({ password: 'current-password' })
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
</auth_methods>
|
|
292
|
+
|
|
293
|
+
---
|
|
294
|
+
|
|
295
|
+
<plugins>
|
|
296
|
+
|
|
297
|
+
## Plugin System
|
|
298
|
+
|
|
299
|
+
| Plugin | Import | 기능 |
|
|
300
|
+
|--------|--------|------|
|
|
301
|
+
| `multiSession` | `better-auth/plugins` | 다중 세션 관리 |
|
|
302
|
+
| `customSession` | `better-auth/plugins` | 세션 필드 확장 |
|
|
303
|
+
| `twoFactor` | `better-auth/plugins` | 2단계 인증 |
|
|
304
|
+
| `captcha` | `better-auth/plugins` | CAPTCHA 검증 |
|
|
305
|
+
|
|
306
|
+
## Multi-Session
|
|
307
|
+
|
|
308
|
+
```typescript
|
|
309
|
+
// ✅ 서버
|
|
310
|
+
import { multiSession } from 'better-auth/plugins'
|
|
311
|
+
|
|
312
|
+
export const auth = betterAuth({
|
|
313
|
+
plugins: [
|
|
314
|
+
multiSession({
|
|
315
|
+
maximumSessions: 5, // 최대 세션 수
|
|
316
|
+
}),
|
|
317
|
+
],
|
|
318
|
+
})
|
|
319
|
+
|
|
320
|
+
// ✅ 클라이언트
|
|
321
|
+
import { multiSessionClient } from 'better-auth/client/plugins'
|
|
322
|
+
|
|
323
|
+
export const authClient = createAuthClient({
|
|
324
|
+
plugins: [multiSessionClient()],
|
|
325
|
+
})
|
|
326
|
+
|
|
327
|
+
// 사용
|
|
328
|
+
const sessions = await authClient.multiSession.listSessions()
|
|
329
|
+
await authClient.multiSession.revokeSession({ sessionId: 'session-id' })
|
|
330
|
+
await authClient.multiSession.revokeOtherSessions()
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
## CAPTCHA
|
|
334
|
+
|
|
335
|
+
```typescript
|
|
336
|
+
// ✅ 서버
|
|
337
|
+
import { captcha } from 'better-auth/plugins'
|
|
338
|
+
|
|
339
|
+
export const auth = betterAuth({
|
|
340
|
+
plugins: [
|
|
341
|
+
captcha({
|
|
342
|
+
provider: 'recaptcha',
|
|
343
|
+
siteKey: process.env.RECAPTCHA_SITE_KEY!,
|
|
344
|
+
secretKey: process.env.RECAPTCHA_SECRET_KEY!,
|
|
345
|
+
protectEndpoints: ['/sign-up/email', '/sign-in/email'],
|
|
346
|
+
}),
|
|
347
|
+
],
|
|
348
|
+
})
|
|
349
|
+
|
|
350
|
+
// ✅ 클라이언트
|
|
351
|
+
import { captchaClient } from 'better-auth/client/plugins'
|
|
352
|
+
|
|
353
|
+
export const authClient = createAuthClient({
|
|
354
|
+
plugins: [
|
|
355
|
+
captchaClient({
|
|
356
|
+
siteKey: process.env.NEXT_PUBLIC_RECAPTCHA_SITE_KEY!,
|
|
357
|
+
}),
|
|
358
|
+
],
|
|
359
|
+
})
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
</plugins>
|
|
363
|
+
|
|
364
|
+
---
|
|
365
|
+
|
|
366
|
+
<advanced>
|
|
367
|
+
|
|
368
|
+
## SIWE (Ethereum)
|
|
369
|
+
|
|
370
|
+
```typescript
|
|
371
|
+
// 서버: siwe({ domain, uri })
|
|
372
|
+
// 클라이언트:
|
|
373
|
+
const { data } = await authClient.siwe.getNonce()
|
|
374
|
+
const message = await authClient.siwe.prepareMessage({ address: '0x...', nonce: data.nonce })
|
|
375
|
+
const signature = await signer.signMessage(message)
|
|
376
|
+
await authClient.siwe.signIn({ message, signature })
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
## Stateless Mode
|
|
380
|
+
|
|
381
|
+
```typescript
|
|
382
|
+
// ✅ DB 없이 소셜 로그인만
|
|
383
|
+
export const auth = betterAuth({
|
|
384
|
+
socialProviders: {
|
|
385
|
+
google: {
|
|
386
|
+
clientId: process.env.GOOGLE_CLIENT_ID!,
|
|
387
|
+
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
|
|
388
|
+
},
|
|
389
|
+
},
|
|
390
|
+
})
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
## Redis Secondary Storage
|
|
394
|
+
|
|
395
|
+
```typescript
|
|
396
|
+
import { Redis } from 'ioredis'
|
|
397
|
+
|
|
398
|
+
const redis = new Redis()
|
|
399
|
+
|
|
400
|
+
export const auth = betterAuth({
|
|
401
|
+
database: prismaAdapter(prisma),
|
|
402
|
+
secondaryStorage: {
|
|
403
|
+
get: async (key: string) => {
|
|
404
|
+
const value = await redis.get(key)
|
|
405
|
+
return value ? JSON.parse(value) : null
|
|
406
|
+
},
|
|
407
|
+
set: async (key: string, value: any, ttl: number) => {
|
|
408
|
+
await redis.set(key, JSON.stringify(value), 'EX', ttl)
|
|
409
|
+
},
|
|
410
|
+
delete: async (key: string) => {
|
|
411
|
+
await redis.del(key)
|
|
412
|
+
},
|
|
413
|
+
},
|
|
414
|
+
})
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
</advanced>
|
|
418
|
+
|
|
419
|
+
---
|
|
420
|
+
|
|
421
|
+
<patterns>
|
|
422
|
+
|
|
423
|
+
## TanStack Start Integration
|
|
424
|
+
|
|
425
|
+
| 패턴 | 용도 |
|
|
426
|
+
|------|------|
|
|
427
|
+
| API Handler | `src/routes/api/auth/$.ts` |
|
|
428
|
+
| Server Function | `createServerFn` + `auth.api.getSession` |
|
|
429
|
+
| Middleware | `auth.api.getSession` + redirect |
|
|
430
|
+
|
|
431
|
+
### Server Function Pattern
|
|
432
|
+
|
|
433
|
+
```typescript
|
|
434
|
+
// ✅ 인증 체크 Server Function
|
|
435
|
+
export const requireAuth = createServerFn({ method: 'GET' })
|
|
436
|
+
.handler(async ({ request }) => {
|
|
437
|
+
const session = await auth.api.getSession({ headers: request.headers })
|
|
438
|
+
if (!session?.user) {
|
|
439
|
+
throw redirect({ to: '/login' })
|
|
440
|
+
}
|
|
441
|
+
return session.user
|
|
442
|
+
})
|
|
443
|
+
|
|
444
|
+
// ✅ 보호된 데이터 조회
|
|
445
|
+
export const getProtectedData = createServerFn({ method: 'GET' })
|
|
446
|
+
.handler(async ({ request }) => {
|
|
447
|
+
const user = await requireAuth()
|
|
448
|
+
return prisma.data.findMany({ where: { userId: user.id } })
|
|
449
|
+
})
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
### Route Protection
|
|
453
|
+
|
|
454
|
+
```typescript
|
|
455
|
+
// ✅ Route Loader
|
|
456
|
+
export const Route = createFileRoute('/dashboard')({
|
|
457
|
+
component: Dashboard,
|
|
458
|
+
async loader() {
|
|
459
|
+
const user = await requireAuth()
|
|
460
|
+
const data = await getProtectedData()
|
|
461
|
+
return { user, data }
|
|
462
|
+
},
|
|
463
|
+
})
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
## Common Patterns
|
|
467
|
+
|
|
468
|
+
| 작업 | 패턴 |
|
|
469
|
+
|------|------|
|
|
470
|
+
| 로그인 | `authClient.signIn.email({ email, password })` |
|
|
471
|
+
| 회원가입 | `authClient.signUp.email({ email, password, name })` |
|
|
472
|
+
| 로그아웃 | `authClient.signOut()` |
|
|
473
|
+
| 세션 조회 | `authClient.getSession()` |
|
|
474
|
+
| 사용자 업데이트 | `authClient.updateUser({ name })` |
|
|
475
|
+
| 비밀번호 재설정 | `authClient.forgetPassword({ email })` → `authClient.resetPassword({ token, password })` |
|
|
476
|
+
|
|
477
|
+
## Do's & Don'ts
|
|
478
|
+
|
|
479
|
+
| ✅ Do | ❌ Don't |
|
|
480
|
+
|-------|----------|
|
|
481
|
+
| `auth.api.getSession()` 서버에서 사용 | 클라이언트에서 직접 세션 조작 |
|
|
482
|
+
| `authClient` 클라이언트에서 사용 | 하드코딩된 시크릿 |
|
|
483
|
+
| 환경변수로 시크릿 관리 | 세션 토큰 로컬스토리지 저장 |
|
|
484
|
+
| HTTPS 프로덕션 필수 | HTTP 프로덕션 배포 |
|
|
485
|
+
| `baseURL` 환경별 설정 | 절대 경로 하드코딩 |
|
|
486
|
+
|
|
487
|
+
</patterns>
|