weifuwu 0.32.0 → 0.33.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.
@@ -1,68 +0,0 @@
1
- import type { Middleware, User } from '../types.ts';
2
- export interface AuthOptions {
3
- /**
4
- * JWT authentication.
5
- *
6
- * @example
7
- * auth({ jwt: { secret: process.env.JWT_SECRET } })
8
- */
9
- jwt?: {
10
- /** HMAC secret for HS256. */
11
- secret: string;
12
- /** Cookie name for the token (default: 'token'). */
13
- cookie?: string;
14
- };
15
- /**
16
- * Simple session authentication via signed cookie.
17
- *
18
- * @example
19
- * auth({ session: { secret: '...' } })
20
- */
21
- session?: {
22
- /** Secret for HMAC cookie signing. */
23
- secret: string;
24
- /** Cookie name (default: 'session'). */
25
- cookie?: string;
26
- /** Load user from session data. */
27
- loadUser: (data: Record<string, unknown>) => Promise<User | null> | User | null;
28
- };
29
- /**
30
- * API key authentication via header.
31
- *
32
- * @example
33
- * auth({ apiKey: { header: 'x-api-key', keys: ['sk-xxx'] } })
34
- */
35
- apiKey?: {
36
- /** Header name (default: 'authorization'). */
37
- header?: string;
38
- /** Prefix to strip (default: 'Bearer '). */
39
- prefix?: string;
40
- /** Validate an API key → User or null. */
41
- validate: (key: string) => Promise<User | null> | User | null;
42
- };
43
- }
44
- /**
45
- * Authentication middleware — injects `ctx.user`.
46
- *
47
- * Supports JWT (HS256), signed session cookies, and API keys.
48
- * When no user is authenticated, requests still proceed —
49
- * check `ctx.user` in your handlers to enforce auth.
50
- *
51
- * @example
52
- * ```ts
53
- * // JWT
54
- * app.use(auth({ jwt: { secret: 'my-secret' } }))
55
- *
56
- * // Session cookie
57
- * app.use(auth({
58
- * session: {
59
- * secret: '...',
60
- * loadUser: async (data) => db.findUser(data.userId),
61
- * },
62
- * }))
63
- *
64
- * // API key
65
- * app.use(auth({ apiKey: { validate: async (key) => db.findByApiKey(key) } }))
66
- * ```
67
- */
68
- export declare function auth(opts: AuthOptions): Middleware;