@draftlab/auth 0.14.0 → 0.15.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.
Files changed (70) hide show
  1. package/dist/adapters/node.d.mts +0 -1
  2. package/dist/client.d.mts +293 -287
  3. package/dist/client.mjs +1 -0
  4. package/dist/core.d.mts +23 -24
  5. package/dist/core.mjs +6 -6
  6. package/dist/error.d.mts +53 -53
  7. package/dist/keys.d.mts +0 -1
  8. package/dist/mutex.d.mts +14 -14
  9. package/dist/provider/apple.d.mts +34 -35
  10. package/dist/provider/code.d.mts +75 -85
  11. package/dist/provider/code.mjs +83 -0
  12. package/dist/provider/discord.d.mts +49 -50
  13. package/dist/provider/facebook.d.mts +49 -50
  14. package/dist/provider/github.d.mts +50 -51
  15. package/dist/provider/gitlab.d.mts +34 -35
  16. package/dist/provider/google.d.mts +49 -50
  17. package/dist/provider/linkedin.d.mts +47 -48
  18. package/dist/provider/magiclink.d.mts +28 -38
  19. package/dist/provider/magiclink.mjs +57 -0
  20. package/dist/provider/microsoft.d.mts +67 -68
  21. package/dist/provider/oauth2.d.mts +75 -76
  22. package/dist/provider/oauth2.mjs +57 -0
  23. package/dist/provider/passkey.d.mts +20 -21
  24. package/dist/provider/password.d.mts +174 -202
  25. package/dist/provider/provider.d.mts +107 -109
  26. package/dist/provider/reddit.d.mts +33 -34
  27. package/dist/provider/slack.d.mts +34 -35
  28. package/dist/provider/spotify.d.mts +34 -35
  29. package/dist/provider/totp.d.mts +43 -44
  30. package/dist/provider/twitch.d.mts +33 -34
  31. package/dist/provider/vercel.d.mts +65 -66
  32. package/dist/revocation.d.mts +29 -30
  33. package/dist/router/context.d.mts +21 -0
  34. package/dist/router/context.mjs +193 -0
  35. package/dist/router/cookies.d.mts +8 -0
  36. package/dist/router/cookies.mjs +13 -0
  37. package/dist/router/index.d.mts +21 -0
  38. package/dist/router/index.mjs +107 -0
  39. package/dist/router/matcher.d.mts +15 -0
  40. package/dist/router/matcher.mjs +76 -0
  41. package/dist/router/middleware/cors.d.mts +15 -0
  42. package/dist/router/middleware/cors.mjs +114 -0
  43. package/dist/router/safe-request.d.mts +52 -0
  44. package/dist/router/safe-request.mjs +160 -0
  45. package/dist/router/types.d.mts +67 -0
  46. package/dist/router/types.mjs +1 -0
  47. package/dist/router/variables.d.mts +12 -0
  48. package/dist/router/variables.mjs +20 -0
  49. package/dist/storage/memory.d.mts +11 -12
  50. package/dist/storage/storage.d.mts +110 -110
  51. package/dist/storage/turso.d.mts +0 -1
  52. package/dist/storage/unstorage.d.mts +0 -1
  53. package/dist/subject.d.mts +0 -1
  54. package/dist/themes/theme.d.mts +101 -101
  55. package/dist/toolkit/client.d.mts +56 -57
  56. package/dist/toolkit/providers/facebook.d.mts +0 -1
  57. package/dist/toolkit/providers/github.d.mts +0 -1
  58. package/dist/toolkit/providers/google.d.mts +0 -1
  59. package/dist/toolkit/storage.d.mts +8 -8
  60. package/dist/ui/base.d.mts +0 -1
  61. package/dist/ui/code.d.mts +5 -6
  62. package/dist/ui/form.d.mts +6 -7
  63. package/dist/ui/icon.d.mts +0 -1
  64. package/dist/ui/magiclink.d.mts +5 -6
  65. package/dist/ui/passkey.d.mts +0 -1
  66. package/dist/ui/password.d.mts +2 -3
  67. package/dist/ui/select.d.mts +0 -1
  68. package/dist/ui/totp.d.mts +0 -1
  69. package/dist/util.d.mts +1 -2
  70. package/package.json +6 -7
@@ -1,9 +1,8 @@
1
+ import { RouterContext } from "../router/types.mjs";
2
+ import { Router } from "../router/index.mjs";
1
3
  import { StorageAdapter } from "../storage/storage.mjs";
2
- import { Router } from "@draftlab/auth-router";
3
- import { RouterContext } from "@draftlab/auth-router/types";
4
4
 
5
5
  //#region src/provider/provider.d.ts
6
-
7
6
  /**
8
7
  * OAuth provider system for Draft Auth.
9
8
  * Defines the interfaces and utilities for implementing authentication providers
@@ -54,35 +53,35 @@ type ProviderRoute = Router;
54
53
  */
55
54
  interface Provider<Properties = Record<string, unknown>> {
56
55
  /**
57
- * Unique identifier for this provider type.
58
- * Used in URLs and provider selection UI.
59
- *
60
- * @example "github", "google", "steam"
61
- */
56
+ * Unique identifier for this provider type.
57
+ * Used in URLs and provider selection UI.
58
+ *
59
+ * @example "github", "google", "steam"
60
+ */
62
61
  readonly type: string;
63
62
  /**
64
- * Initializes the provider by registering required routes.
65
- * Called during issuer setup to configure authorization and callback endpoints.
66
- *
67
- * @param route - Router instance for registering provider endpoints
68
- * @param options - Provider utilities and configuration
69
- *
70
- * @example
71
- * ```ts
72
- * init(routes, ctx) {
73
- * routes.get("/authorize", async (c) => {
74
- * // Redirect to OAuth provider
75
- * return c.redirect(buildAuthUrl())
76
- * })
77
- *
78
- * routes.get("/callback", async (c) => {
79
- * // Process callback and return user data
80
- * const userData = await handleCallback(c)
81
- * return await ctx.success(c, userData)
82
- * })
83
- * }
84
- * ```
85
- */
63
+ * Initializes the provider by registering required routes.
64
+ * Called during issuer setup to configure authorization and callback endpoints.
65
+ *
66
+ * @param route - Router instance for registering provider endpoints
67
+ * @param options - Provider utilities and configuration
68
+ *
69
+ * @example
70
+ * ```ts
71
+ * init(routes, ctx) {
72
+ * routes.get("/authorize", async (c) => {
73
+ * // Redirect to OAuth provider
74
+ * return c.redirect(buildAuthUrl())
75
+ * })
76
+ *
77
+ * routes.get("/callback", async (c) => {
78
+ * // Process callback and return user data
79
+ * const userData = await handleCallback(c)
80
+ * return await ctx.success(c, userData)
81
+ * })
82
+ * }
83
+ * ```
84
+ */
86
85
  init: (route: ProviderRoute, options: ProviderOptions<Properties>) => void;
87
86
  }
88
87
  /**
@@ -93,100 +92,99 @@ interface Provider<Properties = Record<string, unknown>> {
93
92
  */
94
93
  interface ProviderOptions<Properties> {
95
94
  /**
96
- * Name of the provider instance as configured in the issuer.
97
- * Corresponds to the key used in the providers object.
98
- */
95
+ * Name of the provider instance as configured in the issuer.
96
+ * Corresponds to the key used in the providers object.
97
+ */
99
98
  readonly name: string;
100
99
  /**
101
- * Completes the authentication flow with user data.
102
- * Called when the provider successfully authenticates a user.
103
- *
104
- * @param ctx - Router request context
105
- * @param properties - User data extracted from the provider
106
- * @param opts - Optional utilities for session management
107
- * @returns Response that completes the OAuth flow
108
- *
109
- * @example
110
- * ```ts
111
- * const userData = { userId: "123", email: "user@example.com" }
112
- * return await ctx.success(c, userData)
113
- * ```
114
- */
100
+ * Completes the authentication flow with user data.
101
+ * Called when the provider successfully authenticates a user.
102
+ *
103
+ * @param ctx - Router request context
104
+ * @param properties - User data extracted from the provider
105
+ * @param opts - Optional utilities for session management
106
+ * @returns Response that completes the OAuth flow
107
+ *
108
+ * @example
109
+ * ```ts
110
+ * const userData = { userId: "123", email: "user@example.com" }
111
+ * return await ctx.success(c, userData)
112
+ * ```
113
+ */
115
114
  success: (ctx: RouterContext, properties: Properties, opts?: {
116
- /** Function to invalidate existing user sessions */
117
- readonly invalidate?: (subject: string) => Promise<void>;
115
+ /** Function to invalidate existing user sessions */readonly invalidate?: (subject: string) => Promise<void>;
118
116
  }) => Promise<Response>;
119
117
  /**
120
- * Forwards a response through the provider context.
121
- * Used for redirects and custom responses within the OAuth flow.
122
- *
123
- * @param ctx - Router request context
124
- * @param response - Response to forward
125
- * @returns Forwarded response
126
- */
118
+ * Forwards a response through the provider context.
119
+ * Used for redirects and custom responses within the OAuth flow.
120
+ *
121
+ * @param ctx - Router request context
122
+ * @param response - Response to forward
123
+ * @returns Forwarded response
124
+ */
127
125
  forward: (ctx: RouterContext, response: Response) => Response;
128
126
  /**
129
- * Stores a temporary value with expiration for the current session.
130
- * Useful for storing OAuth state, PKCE verifiers, and other temporary data.
131
- *
132
- * @param ctx - Router request context
133
- * @param key - Storage key identifier
134
- * @param maxAge - TTL in seconds
135
- * @param value - Value to store
136
- *
137
- * @example
138
- * ```ts
139
- * // Store OAuth state for 10 minutes
140
- * await ctx.set(c, "oauth_state", 600, { state, redirectUri })
141
- * ```
142
- */
127
+ * Stores a temporary value with expiration for the current session.
128
+ * Useful for storing OAuth state, PKCE verifiers, and other temporary data.
129
+ *
130
+ * @param ctx - Router request context
131
+ * @param key - Storage key identifier
132
+ * @param maxAge - TTL in seconds
133
+ * @param value - Value to store
134
+ *
135
+ * @example
136
+ * ```ts
137
+ * // Store OAuth state for 10 minutes
138
+ * await ctx.set(c, "oauth_state", 600, { state, redirectUri })
139
+ * ```
140
+ */
143
141
  set: <T>(ctx: RouterContext, key: string, maxAge: number, value: T) => Promise<void>;
144
142
  /**
145
- * Retrieves a previously stored temporary value.
146
- *
147
- * @param ctx - Router request context
148
- * @param key - Storage key identifier
149
- * @returns Promise resolving to the stored value or undefined if not found/expired
150
- *
151
- * @example
152
- * ```ts
153
- * const oauthState = await ctx.get<OAuthState>(c, "oauth_state")
154
- * if (!oauthState) {
155
- * throw new Error("OAuth state expired")
156
- * }
157
- * ```
158
- */
143
+ * Retrieves a previously stored temporary value.
144
+ *
145
+ * @param ctx - Router request context
146
+ * @param key - Storage key identifier
147
+ * @returns Promise resolving to the stored value or undefined if not found/expired
148
+ *
149
+ * @example
150
+ * ```ts
151
+ * const oauthState = await ctx.get<OAuthState>(c, "oauth_state")
152
+ * if (!oauthState) {
153
+ * throw new Error("OAuth state expired")
154
+ * }
155
+ * ```
156
+ */
159
157
  get: <T>(ctx: RouterContext, key: string) => Promise<T | undefined>;
160
158
  /**
161
- * Removes a stored temporary value.
162
- *
163
- * @param ctx - Router request context
164
- * @param key - Storage key identifier
165
- *
166
- * @example
167
- * ```ts
168
- * // Clean up OAuth state after use
169
- * await ctx.unset(c, "oauth_state")
170
- * ```
171
- */
159
+ * Removes a stored temporary value.
160
+ *
161
+ * @param ctx - Router request context
162
+ * @param key - Storage key identifier
163
+ *
164
+ * @example
165
+ * ```ts
166
+ * // Clean up OAuth state after use
167
+ * await ctx.unset(c, "oauth_state")
168
+ * ```
169
+ */
172
170
  unset: (ctx: RouterContext, key: string) => Promise<void>;
173
171
  /**
174
- * Invalidates all sessions for a given subject (user).
175
- * Forces logout across all devices and applications.
176
- *
177
- * @param subject - Subject identifier to invalidate
178
- *
179
- * @example
180
- * ```ts
181
- * // Force logout on password change
182
- * await ctx.invalidate(userId)
183
- * ```
184
- */
172
+ * Invalidates all sessions for a given subject (user).
173
+ * Forces logout across all devices and applications.
174
+ *
175
+ * @param subject - Subject identifier to invalidate
176
+ *
177
+ * @example
178
+ * ```ts
179
+ * // Force logout on password change
180
+ * await ctx.invalidate(userId)
181
+ * ```
182
+ */
185
183
  invalidate: (subject: string) => Promise<void>;
186
184
  /**
187
- * Storage adapter for persistent data operations.
188
- * Provides access to the configured storage backend.
189
- */
185
+ * Storage adapter for persistent data operations.
186
+ * Provides access to the configured storage backend.
187
+ */
190
188
  readonly storage: StorageAdapter;
191
189
  }
192
190
  /**
@@ -2,50 +2,49 @@ import { Provider } from "./provider.mjs";
2
2
  import { Oauth2UserData, Oauth2WrappedConfig } from "./oauth2.mjs";
3
3
 
4
4
  //#region src/provider/reddit.d.ts
5
-
6
5
  /**
7
6
  * Configuration options for Reddit OAuth 2.0 provider.
8
7
  * Extends the base OAuth 2.0 configuration with Reddit-specific documentation.
9
8
  */
10
9
  interface RedditConfig extends Oauth2WrappedConfig {
11
10
  /**
12
- * Reddit app client ID.
13
- * Get this from your Reddit application preferences at https://www.reddit.com/prefs/apps
14
- *
15
- * @example
16
- * ```ts
17
- * {
18
- * clientID: "abcdef123456"
19
- * }
20
- * ```
21
- */
11
+ * Reddit app client ID.
12
+ * Get this from your Reddit application preferences at https://www.reddit.com/prefs/apps
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * {
17
+ * clientID: "abcdef123456"
18
+ * }
19
+ * ```
20
+ */
22
21
  readonly clientID: string;
23
22
  /**
24
- * Reddit app client secret.
25
- * Keep this secure and never expose it to client-side code.
26
- *
27
- * @example
28
- * ```ts
29
- * {
30
- * clientSecret: process.env.REDDIT_CLIENT_SECRET
31
- * }
32
- * ```
33
- */
23
+ * Reddit app client secret.
24
+ * Keep this secure and never expose it to client-side code.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * {
29
+ * clientSecret: process.env.REDDIT_CLIENT_SECRET
30
+ * }
31
+ * ```
32
+ */
34
33
  readonly clientSecret: string;
35
34
  /**
36
- * Reddit OAuth scopes to request access for.
37
- * Determines what data and actions your app can access.
38
- *
39
- * @example
40
- * ```ts
41
- * {
42
- * scopes: [
43
- * "identity", // Access user identity
44
- * "read" // Read private data
45
- * ]
46
- * }
47
- * ```
48
- */
35
+ * Reddit OAuth scopes to request access for.
36
+ * Determines what data and actions your app can access.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * {
41
+ * scopes: [
42
+ * "identity", // Access user identity
43
+ * "read" // Read private data
44
+ * ]
45
+ * }
46
+ * ```
47
+ */
49
48
  readonly scopes: string[];
50
49
  }
51
50
  /**
@@ -2,51 +2,50 @@ import { Provider } from "./provider.mjs";
2
2
  import { Oauth2UserData, Oauth2WrappedConfig } from "./oauth2.mjs";
3
3
 
4
4
  //#region src/provider/slack.d.ts
5
-
6
5
  /**
7
6
  * Configuration options for Slack OAuth 2.0 provider.
8
7
  * Extends the base OAuth 2.0 configuration with Slack-specific documentation.
9
8
  */
10
9
  interface SlackConfig extends Oauth2WrappedConfig {
11
10
  /**
12
- * Slack app client ID.
13
- * Get this from your Slack App settings at https://api.slack.com/apps
14
- *
15
- * @example
16
- * ```ts
17
- * {
18
- * clientID: "123456789.1234567890"
19
- * }
20
- * ```
21
- */
11
+ * Slack app client ID.
12
+ * Get this from your Slack App settings at https://api.slack.com/apps
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * {
17
+ * clientID: "123456789.1234567890"
18
+ * }
19
+ * ```
20
+ */
22
21
  readonly clientID: string;
23
22
  /**
24
- * Slack app client secret.
25
- * Keep this secure and never expose it to client-side code.
26
- *
27
- * @example
28
- * ```ts
29
- * {
30
- * clientSecret: process.env.SLACK_CLIENT_SECRET
31
- * }
32
- * ```
33
- */
23
+ * Slack app client secret.
24
+ * Keep this secure and never expose it to client-side code.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * {
29
+ * clientSecret: process.env.SLACK_CLIENT_SECRET
30
+ * }
31
+ * ```
32
+ */
34
33
  readonly clientSecret: string;
35
34
  /**
36
- * Slack OAuth scopes to request access for.
37
- * Determines what data and actions your app can access.
38
- *
39
- * @example
40
- * ```ts
41
- * {
42
- * scopes: [
43
- * "users:read", // Access to user profiles
44
- * "users:read.email", // Access user emails
45
- * "team:read" // Access team information
46
- * ]
47
- * }
48
- * ```
49
- */
35
+ * Slack OAuth scopes to request access for.
36
+ * Determines what data and actions your app can access.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * {
41
+ * scopes: [
42
+ * "users:read", // Access to user profiles
43
+ * "users:read.email", // Access user emails
44
+ * "team:read" // Access team information
45
+ * ]
46
+ * }
47
+ * ```
48
+ */
50
49
  readonly scopes: string[];
51
50
  }
52
51
  /**
@@ -2,51 +2,50 @@ import { Provider } from "./provider.mjs";
2
2
  import { Oauth2UserData, Oauth2WrappedConfig } from "./oauth2.mjs";
3
3
 
4
4
  //#region src/provider/spotify.d.ts
5
-
6
5
  /**
7
6
  * Configuration options for Spotify OAuth 2.0 provider.
8
7
  * Extends the base OAuth 2.0 configuration with Spotify-specific documentation.
9
8
  */
10
9
  interface SpotifyConfig extends Oauth2WrappedConfig {
11
10
  /**
12
- * Spotify app client ID.
13
- * Get this from your Spotify App at https://developer.spotify.com/dashboard
14
- *
15
- * @example
16
- * ```ts
17
- * {
18
- * clientID: "abcdef123456"
19
- * }
20
- * ```
21
- */
11
+ * Spotify app client ID.
12
+ * Get this from your Spotify App at https://developer.spotify.com/dashboard
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * {
17
+ * clientID: "abcdef123456"
18
+ * }
19
+ * ```
20
+ */
22
21
  readonly clientID: string;
23
22
  /**
24
- * Spotify app client secret.
25
- * Keep this secure and never expose it to client-side code.
26
- *
27
- * @example
28
- * ```ts
29
- * {
30
- * clientSecret: process.env.SPOTIFY_CLIENT_SECRET
31
- * }
32
- * ```
33
- */
23
+ * Spotify app client secret.
24
+ * Keep this secure and never expose it to client-side code.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * {
29
+ * clientSecret: process.env.SPOTIFY_CLIENT_SECRET
30
+ * }
31
+ * ```
32
+ */
34
33
  readonly clientSecret: string;
35
34
  /**
36
- * Spotify OAuth scopes to request access for.
37
- * Determines what data and actions your app can access.
38
- *
39
- * @example
40
- * ```ts
41
- * {
42
- * scopes: [
43
- * "user-read-private", // Access private user data
44
- * "user-read-email", // Access user email
45
- * "user-top-read" // Read top artists and tracks
46
- * ]
47
- * }
48
- * ```
49
- */
35
+ * Spotify OAuth scopes to request access for.
36
+ * Determines what data and actions your app can access.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * {
41
+ * scopes: [
42
+ * "user-read-private", // Access private user data
43
+ * "user-read-email", // Access user email
44
+ * "user-top-read" // Read top artists and tracks
45
+ * ]
46
+ * }
47
+ * ```
48
+ */
50
49
  readonly scopes: string[];
51
50
  }
52
51
  /**
@@ -1,7 +1,6 @@
1
1
  import { Provider } from "./provider.mjs";
2
2
 
3
3
  //#region src/provider/totp.d.ts
4
-
5
4
  /**
6
5
  * TOTP data model stored in the database.
7
6
  * Contains the user's TOTP configuration and backup codes.
@@ -24,69 +23,69 @@ interface TOTPModel {
24
23
  */
25
24
  interface TOTPProviderConfig {
26
25
  /**
27
- * The human-readable name of the issuer (your application).
28
- * This appears in authenticator apps next to the TOTP entry.
29
- */
26
+ * The human-readable name of the issuer (your application).
27
+ * This appears in authenticator apps next to the TOTP entry.
28
+ */
30
29
  issuer: string;
31
30
  /**
32
- * Custom authorize handler that generates the UI for TOTP login.
33
- * Called when user wants to login with TOTP (main page).
34
- *
35
- * @param req - The HTTP request object
36
- * @param error - Optional error message to display
37
- */
31
+ * Custom authorize handler that generates the UI for TOTP login.
32
+ * Called when user wants to login with TOTP (main page).
33
+ *
34
+ * @param req - The HTTP request object
35
+ * @param error - Optional error message to display
36
+ */
38
37
  authorize: (req: Request, error?: string) => Promise<Response>;
39
38
  /**
40
- * Custom register handler that generates the UI for TOTP setup.
41
- * Called when user is setting up TOTP for the first time.
42
- *
43
- * @param req - The HTTP request object
44
- * @param qrCodeUrl - The otpauth:// URL for QR code generation
45
- * @param secret - The raw secret (for manual entry)
46
- * @param backupCodes - Array of backup/recovery codes
47
- * @param error - Optional error message to display
48
- */
39
+ * Custom register handler that generates the UI for TOTP setup.
40
+ * Called when user is setting up TOTP for the first time.
41
+ *
42
+ * @param req - The HTTP request object
43
+ * @param qrCodeUrl - The otpauth:// URL for QR code generation
44
+ * @param secret - The raw secret (for manual entry)
45
+ * @param backupCodes - Array of backup/recovery codes
46
+ * @param error - Optional error message to display
47
+ */
49
48
  register: (req: Request, qrCodeUrl: string, secret: string, backupCodes: string[], error?: string, email?: string) => Promise<Response>;
50
49
  /**
51
- * Custom recovery handler that generates the UI for backup code entry.
52
- * Called when user wants to use a recovery code instead of TOTP.
53
- *
54
- * @param req - The HTTP request object
55
- * @param error - Optional error message to display
56
- */
50
+ * Custom recovery handler that generates the UI for backup code entry.
51
+ * Called when user wants to use a recovery code instead of TOTP.
52
+ *
53
+ * @param req - The HTTP request object
54
+ * @param error - Optional error message to display
55
+ */
57
56
  recovery: (req: Request, error?: string) => Promise<Response>;
58
57
  /**
59
- * Optional TOTP algorithm. Defaults to SHA1 for maximum compatibility.
60
- * Most authenticator apps support SHA1, fewer support SHA256/SHA512.
61
- */
58
+ * Optional TOTP algorithm. Defaults to SHA1 for maximum compatibility.
59
+ * Most authenticator apps support SHA1, fewer support SHA256/SHA512.
60
+ */
62
61
  algorithm?: "SHA1" | "SHA256" | "SHA512";
63
62
  /**
64
- * Optional number of digits in TOTP codes. Defaults to 6.
65
- * Some apps support 8 digits for increased security.
66
- */
63
+ * Optional number of digits in TOTP codes. Defaults to 6.
64
+ * Some apps support 8 digits for increased security.
65
+ */
67
66
  digits?: 6 | 8;
68
67
  /**
69
- * Optional validity period for TOTP codes in seconds. Defaults to 30.
70
- * Standard is 30 seconds, some high-security apps use 60.
71
- */
68
+ * Optional validity period for TOTP codes in seconds. Defaults to 30.
69
+ * Standard is 30 seconds, some high-security apps use 60.
70
+ */
72
71
  period?: number;
73
72
  /**
74
- * Optional time window tolerance for clock drift. Defaults to 1.
75
- * Allows tokens from previous/next time window to be valid.
76
- */
73
+ * Optional time window tolerance for clock drift. Defaults to 1.
74
+ * Allows tokens from previous/next time window to be valid.
75
+ */
77
76
  window?: number;
78
77
  /**
79
- * Optional number of backup codes to generate. Defaults to 10.
80
- */
78
+ * Optional number of backup codes to generate. Defaults to 10.
79
+ */
81
80
  backupCodesCount?: number;
82
81
  /**
83
- * Optional function to check if a user is allowed to set up TOTP.
84
- */
82
+ * Optional function to check if a user is allowed to set up TOTP.
83
+ */
85
84
  userCanSetupTOTP?: (userId: string, req: Request) => Promise<boolean>;
86
85
  /**
87
- * Optional custom label generator for TOTP entries.
88
- * Defaults to using the userId as the label.
89
- */
86
+ * Optional custom label generator for TOTP entries.
87
+ * Defaults to using the userId as the label.
88
+ */
90
89
  generateLabel?: (userId: string) => Promise<string>;
91
90
  }
92
91
  /**