@lenne.tech/nest-server 11.7.1 → 11.7.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.
Files changed (60) hide show
  1. package/dist/core/common/interfaces/server-options.interface.d.ts +18 -15
  2. package/dist/core/modules/auth/core-auth.controller.js +2 -2
  3. package/dist/core/modules/auth/core-auth.controller.js.map +1 -1
  4. package/dist/core/modules/auth/core-auth.resolver.js +2 -2
  5. package/dist/core/modules/auth/core-auth.resolver.js.map +1 -1
  6. package/dist/core/modules/auth/services/legacy-auth-rate-limiter.service.js +1 -1
  7. package/dist/core/modules/auth/services/legacy-auth-rate-limiter.service.js.map +1 -1
  8. package/dist/core/modules/better-auth/better-auth-rate-limiter.service.js +1 -1
  9. package/dist/core/modules/better-auth/better-auth-rate-limiter.service.js.map +1 -1
  10. package/dist/core/modules/better-auth/better-auth-user.mapper.js +7 -55
  11. package/dist/core/modules/better-auth/better-auth-user.mapper.js.map +1 -1
  12. package/dist/core/modules/better-auth/better-auth.config.js +29 -10
  13. package/dist/core/modules/better-auth/better-auth.config.js.map +1 -1
  14. package/dist/core/modules/better-auth/better-auth.middleware.d.ts +1 -0
  15. package/dist/core/modules/better-auth/better-auth.middleware.js +55 -1
  16. package/dist/core/modules/better-auth/better-auth.middleware.js.map +1 -1
  17. package/dist/core/modules/better-auth/better-auth.module.d.ts +1 -1
  18. package/dist/core/modules/better-auth/better-auth.module.js +46 -18
  19. package/dist/core/modules/better-auth/better-auth.module.js.map +1 -1
  20. package/dist/core/modules/better-auth/better-auth.resolver.js +0 -11
  21. package/dist/core/modules/better-auth/better-auth.resolver.js.map +1 -1
  22. package/dist/core/modules/better-auth/better-auth.service.d.ts +22 -1
  23. package/dist/core/modules/better-auth/better-auth.service.js +209 -8
  24. package/dist/core/modules/better-auth/better-auth.service.js.map +1 -1
  25. package/dist/core/modules/better-auth/better-auth.types.d.ts +2 -0
  26. package/dist/core/modules/better-auth/better-auth.types.js.map +1 -1
  27. package/dist/core/modules/better-auth/core-better-auth.resolver.d.ts +5 -0
  28. package/dist/core/modules/better-auth/core-better-auth.resolver.js +58 -12
  29. package/dist/core/modules/better-auth/core-better-auth.resolver.js.map +1 -1
  30. package/dist/core.module.js +6 -3
  31. package/dist/core.module.js.map +1 -1
  32. package/dist/server/modules/better-auth/better-auth.module.d.ts +1 -1
  33. package/dist/server/modules/better-auth/better-auth.module.js +2 -1
  34. package/dist/server/modules/better-auth/better-auth.module.js.map +1 -1
  35. package/dist/server/modules/better-auth/better-auth.resolver.d.ts +3 -0
  36. package/dist/server/modules/better-auth/better-auth.resolver.js +14 -11
  37. package/dist/server/modules/better-auth/better-auth.resolver.js.map +1 -1
  38. package/dist/server/modules/user/user.controller.js +0 -8
  39. package/dist/server/modules/user/user.controller.js.map +1 -1
  40. package/dist/tsconfig.build.tsbuildinfo +1 -1
  41. package/package.json +1 -1
  42. package/src/core/common/interfaces/server-options.interface.ts +129 -58
  43. package/src/core/modules/auth/core-auth.controller.ts +2 -2
  44. package/src/core/modules/auth/core-auth.resolver.ts +2 -2
  45. package/src/core/modules/auth/services/legacy-auth-rate-limiter.service.ts +1 -1
  46. package/src/core/modules/better-auth/INTEGRATION-CHECKLIST.md +12 -11
  47. package/src/core/modules/better-auth/README.md +82 -43
  48. package/src/core/modules/better-auth/better-auth-rate-limiter.service.ts +1 -1
  49. package/src/core/modules/better-auth/better-auth-user.mapper.ts +9 -77
  50. package/src/core/modules/better-auth/better-auth.config.ts +45 -15
  51. package/src/core/modules/better-auth/better-auth.middleware.ts +85 -2
  52. package/src/core/modules/better-auth/better-auth.module.ts +83 -27
  53. package/src/core/modules/better-auth/better-auth.resolver.ts +0 -11
  54. package/src/core/modules/better-auth/better-auth.service.ts +367 -12
  55. package/src/core/modules/better-auth/better-auth.types.ts +16 -0
  56. package/src/core/modules/better-auth/core-better-auth.resolver.ts +111 -16
  57. package/src/core.module.ts +9 -3
  58. package/src/server/modules/better-auth/better-auth.module.ts +9 -3
  59. package/src/server/modules/better-auth/better-auth.resolver.ts +9 -11
  60. package/src/server/modules/user/user.controller.ts +1 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lenne.tech/nest-server",
3
- "version": "11.7.1",
3
+ "version": "11.7.2",
4
4
  "description": "Modern, fast, powerful Node.js web framework in TypeScript based on Nest with a GraphQL API and a connection to MongoDB (or other databases).",
5
5
  "keywords": [
6
6
  "node",
@@ -274,22 +274,29 @@ export interface IBetterAuth {
274
274
 
275
275
  /**
276
276
  * JWT plugin configuration for API clients.
277
- * Enabled by default when this config block is present.
278
- * Set `enabled: false` to explicitly disable.
277
+ *
278
+ * **Default: Enabled** - JWT is enabled by default when BetterAuth is enabled.
279
+ * This ensures a minimal config (`betterAuth: true`) provides full functionality.
280
+ *
281
+ * Accepts:
282
+ * - `true` or `{}`: Enable with defaults (same as not specifying)
283
+ * - `{ expiresIn: '1h' }`: Enable with custom settings
284
+ * - `false` or `{ enabled: false }`: Explicitly disable
285
+ * - `undefined`: Enabled with defaults (JWT is on by default)
286
+ *
287
+ * @example
288
+ * ```typescript
289
+ * // JWT is enabled by default, no config needed
290
+ * betterAuth: true,
291
+ *
292
+ * // Customize JWT expiry
293
+ * betterAuth: { jwt: { expiresIn: '1h' } },
294
+ *
295
+ * // Explicitly disable JWT (session-only mode)
296
+ * betterAuth: { jwt: false },
297
+ * ```
279
298
  */
280
- jwt?: {
281
- /**
282
- * Whether JWT plugin is enabled.
283
- * @default true (when jwt config block is present)
284
- */
285
- enabled?: boolean;
286
-
287
- /**
288
- * JWT expiration time
289
- * @default '15m'
290
- */
291
- expiresIn?: string;
292
- };
299
+ jwt?: boolean | IBetterAuthJwtConfig;
293
300
 
294
301
  /**
295
302
  * Advanced Better-Auth options passthrough.
@@ -322,34 +329,22 @@ export interface IBetterAuth {
322
329
 
323
330
  /**
324
331
  * Passkey/WebAuthn configuration.
325
- * Enabled by default when this config block is present.
326
- * Set `enabled: false` to explicitly disable.
332
+ *
333
+ * Accepts:
334
+ * - `true` or `{}`: Enable with defaults
335
+ * - `{ rpName: 'My App' }`: Enable with custom settings
336
+ * - `false` or `{ enabled: false }`: Disable
337
+ * - `undefined`: Disabled (default)
338
+ *
339
+ * @example
340
+ * ```typescript
341
+ * passkey: true, // Enable with defaults
342
+ * passkey: {}, // Enable with defaults
343
+ * passkey: { rpName: 'My App', rpId: 'example.com' }, // Enable with custom settings
344
+ * passkey: false, // Disable
345
+ * ```
327
346
  */
328
- passkey?: {
329
- /**
330
- * Whether passkey authentication is enabled.
331
- * @default true (when passkey config block is present)
332
- */
333
- enabled?: boolean;
334
-
335
- /**
336
- * Origin URL for WebAuthn
337
- * e.g. 'http://localhost:3000'
338
- */
339
- origin?: string;
340
-
341
- /**
342
- * Relying Party ID (usually the domain)
343
- * e.g. 'localhost' or 'example.com'
344
- */
345
- rpId?: string;
346
-
347
- /**
348
- * Relying Party Name (displayed to users)
349
- * e.g. 'My Application'
350
- */
351
- rpName?: string;
352
- };
347
+ passkey?: boolean | IBetterAuthPasskeyConfig;
353
348
 
354
349
  /**
355
350
  * Additional Better-Auth plugins to include.
@@ -410,22 +405,68 @@ export interface IBetterAuth {
410
405
 
411
406
  /**
412
407
  * Two-factor authentication configuration.
413
- * Enabled by default when this config block is present.
414
- * Set `enabled: false` to explicitly disable.
408
+ *
409
+ * Accepts:
410
+ * - `true` or `{}`: Enable with defaults
411
+ * - `{ appName: 'My App' }`: Enable with custom settings
412
+ * - `false` or `{ enabled: false }`: Disable
413
+ * - `undefined`: Disabled (default)
414
+ *
415
+ * @example
416
+ * ```typescript
417
+ * twoFactor: true, // Enable with defaults
418
+ * twoFactor: {}, // Enable with defaults
419
+ * twoFactor: { appName: 'My App' }, // Enable with custom app name
420
+ * twoFactor: false, // Disable
421
+ * ```
415
422
  */
416
- twoFactor?: {
417
- /**
418
- * App name shown in authenticator apps
419
- * e.g. 'My Application'
420
- */
421
- appName?: string;
423
+ twoFactor?: boolean | IBetterAuthTwoFactorConfig;
424
+ }
422
425
 
423
- /**
424
- * Whether 2FA is enabled.
425
- * @default true (when twoFactor config block is present)
426
- */
427
- enabled?: boolean;
428
- };
426
+ /**
427
+ * JWT plugin configuration for Better-Auth
428
+ */
429
+ export interface IBetterAuthJwtConfig {
430
+ /**
431
+ * Whether JWT plugin is enabled.
432
+ * @default true (when config block is present)
433
+ */
434
+ enabled?: boolean;
435
+
436
+ /**
437
+ * JWT expiration time
438
+ * @default '15m'
439
+ */
440
+ expiresIn?: string;
441
+ }
442
+
443
+ /**
444
+ * Passkey/WebAuthn plugin configuration for Better-Auth
445
+ */
446
+ export interface IBetterAuthPasskeyConfig {
447
+ /**
448
+ * Whether passkey authentication is enabled.
449
+ * @default true (when config block is present)
450
+ */
451
+ enabled?: boolean;
452
+
453
+ /**
454
+ * Origin URL for WebAuthn
455
+ * e.g. 'http://localhost:3000'
456
+ */
457
+ origin?: string;
458
+
459
+ /**
460
+ * Relying Party ID (usually the domain)
461
+ * e.g. 'localhost' or 'example.com'
462
+ */
463
+ rpId?: string;
464
+
465
+ /**
466
+ * Relying Party Name (displayed to users)
467
+ * e.g. 'My Application'
468
+ */
469
+ rpName?: string;
429
470
  }
430
471
 
431
472
  /**
@@ -505,6 +546,23 @@ export interface IBetterAuthSocialProvider {
505
546
  enabled?: boolean;
506
547
  }
507
548
 
549
+ /**
550
+ * Two-factor authentication plugin configuration for Better-Auth
551
+ */
552
+ export interface IBetterAuthTwoFactorConfig {
553
+ /**
554
+ * App name shown in authenticator apps
555
+ * e.g. 'My Application'
556
+ */
557
+ appName?: string;
558
+
559
+ /**
560
+ * Whether 2FA is enabled.
561
+ * @default true (when config block is present)
562
+ */
563
+ enabled?: boolean;
564
+ }
565
+
508
566
  /**
509
567
  * Interface for additional user fields in Better-Auth
510
568
  * @see https://www.better-auth.com/docs/concepts/users-accounts#additional-fields
@@ -598,10 +656,23 @@ export interface IServerOptions {
598
656
  automaticObjectIdFiltering?: boolean;
599
657
 
600
658
  /**
601
- * Configuration for better-auth authentication framework
659
+ * Configuration for better-auth authentication framework.
602
660
  * See: https://better-auth.com
661
+ *
662
+ * Accepts:
663
+ * - `true`: Enable with all defaults (including JWT)
664
+ * - `false`: Disable BetterAuth completely
665
+ * - `{ ... }`: Enable with custom configuration
666
+ * - `undefined`: Disabled (default for backward compatibility)
667
+ *
668
+ * @example
669
+ * ```typescript
670
+ * betterAuth: true, // Enable with defaults (JWT enabled)
671
+ * betterAuth: { baseUrl: 'https://example.com' }, // Custom config
672
+ * betterAuth: false, // Explicitly disabled
673
+ * ```
603
674
  */
604
- betterAuth?: IBetterAuth;
675
+ betterAuth?: boolean | IBetterAuth;
605
676
 
606
677
  /**
607
678
  * Configuration for Brevo
@@ -101,8 +101,8 @@ export class CoreAuthController {
101
101
  @ApiQuery({ description: 'If all devices should be logged out,', name: 'allDevices', required: false, type: Boolean })
102
102
  @ApiTooManyRequestsResponse({ description: 'Rate limit exceeded' })
103
103
  @Get('logout')
104
- @Roles(RoleEnum.S_EVERYONE)
105
- @UseGuards(LegacyAuthRateLimitGuard, AuthGuard(AuthGuardStrategy.JWT))
104
+ @Roles(RoleEnum.S_USER)
105
+ @UseGuards(LegacyAuthRateLimitGuard)
106
106
  async logout(
107
107
  @CurrentUser() currentUser: ICoreAuthUser,
108
108
  @Tokens('token') token: string,
@@ -92,8 +92,8 @@ export class CoreAuthResolver {
92
92
  * @throws LegacyAuthDisabledException if legacy endpoints are disabled
93
93
  */
94
94
  @Mutation(() => Boolean, { description: 'Logout user (from specific device)' })
95
- @Roles(RoleEnum.S_EVERYONE)
96
- @UseGuards(LegacyAuthRateLimitGuard, AuthGuard(AuthGuardStrategy.JWT))
95
+ @Roles(RoleEnum.S_USER)
96
+ @UseGuards(LegacyAuthRateLimitGuard)
97
97
  async logout(
98
98
  @CurrentUser() currentUser: ICoreAuthUser,
99
99
  @Context() ctx: { res: ResponseType },
@@ -114,7 +114,7 @@ export class LegacyAuthRateLimiter implements OnModuleInit {
114
114
  };
115
115
 
116
116
  if (this.config.enabled) {
117
- this.logger.log(
117
+ this.logger.debug(
118
118
  `Legacy Auth rate limiting enabled: ${this.config.max} requests per ${this.config.windowSeconds}s`,
119
119
  );
120
120
  }
@@ -54,7 +54,9 @@ https://github.com/lenneTech/nest-server/tree/develop/src/server/modules/better-
54
54
  **Copy from:** `node_modules/@lenne.tech/nest-server/src/server/modules/better-auth/better-auth.resolver.ts`
55
55
 
56
56
  **WHY must ALL decorators be re-declared?**
57
- GraphQL schema is built from decorators at compile time. The parent class (`CoreBetterAuthResolver`) is marked as `isAbstract: true`, so its methods are not registered in the schema. You MUST re-declare `@Query`, `@Mutation`, `@Roles`, `@UseGuards` decorators in the child class for the methods to appear in the GraphQL schema.
57
+ GraphQL schema is built from decorators at compile time. The parent class (`CoreBetterAuthResolver`) is marked as `isAbstract: true`, so its methods are not registered in the schema. You MUST re-declare `@Query`, `@Mutation`, `@Roles` decorators in the child class for the methods to appear in the GraphQL schema.
58
+
59
+ **Note:** `@UseGuards(AuthGuard(JWT))` is NOT needed when using `@Roles(S_USER)` or `@Roles(ADMIN)` because `RolesGuard` already extends `AuthGuard(JWT)` internally.
58
60
 
59
61
  ---
60
62
 
@@ -136,13 +138,14 @@ const config = {
136
138
  enabled: false,
137
139
  },
138
140
  },
139
- // BetterAuth configuration
141
+ // BetterAuth configuration (minimal - JWT enabled by default)
142
+ betterAuth: true, // or betterAuth: {} for same effect
143
+
144
+ // OR with optional features:
140
145
  betterAuth: {
141
- // enabled: true (default)
142
- // basePath: '/iam' (default)
143
- jwt: {}, // Enable JWT tokens
144
- twoFactor: {}, // Enable 2FA
145
- passkey: {}, // Enable Passkeys
146
+ twoFactor: {}, // Enable 2FA (opt-in)
147
+ passkey: {}, // Enable Passkeys (opt-in)
148
+ // JWT is already enabled by default
146
149
  },
147
150
  };
148
151
  ```
@@ -156,10 +159,8 @@ const config = {
156
159
  enabled: true, // Default - can disable after migration
157
160
  },
158
161
  },
159
- // BetterAuth configuration
160
- betterAuth: {
161
- // ... same as above
162
- },
162
+ // BetterAuth configuration (JWT enabled by default)
163
+ betterAuth: true, // Minimal config, or use object for more options
163
164
  };
164
165
  ```
165
166
 
@@ -10,8 +10,11 @@ Integration of the [better-auth](https://better-auth.com) authentication framewo
10
10
  CoreModule.forRoot(envConfig), // IAM-only (new projects)
11
11
  BetterAuthModule.forRoot({ config: envConfig.betterAuth, fallbackSecrets: [envConfig.jwt?.secret] }),
12
12
 
13
- // 3. Configure in config.env.ts:
14
- betterAuth: { jwt: {}, twoFactor: {}, passkey: {} }
13
+ // 3. Configure in config.env.ts (minimal - JWT enabled by default):
14
+ betterAuth: true // or betterAuth: {} for same effect
15
+
16
+ // With optional features:
17
+ betterAuth: { twoFactor: {}, passkey: {} }
15
18
  ```
16
19
 
17
20
  **Quick Links:** [Integration Checklist](./INTEGRATION-CHECKLIST.md) | [REST API](#rest-api-endpoints) | [GraphQL API](#graphql-api) | [Configuration](#configuration)
@@ -36,11 +39,11 @@ betterAuth: { jwt: {}, twoFactor: {}, passkey: {} }
36
39
 
37
40
  ## Features
38
41
 
39
- ### Built-in Plugins (Explicit Configuration)
42
+ ### Built-in Plugins
40
43
 
41
- - **JWT Tokens** - For API clients and stateless authentication
42
- - **Two-Factor Authentication (2FA)** - TOTP-based second factor
43
- - **Passkey/WebAuthn** - Passwordless authentication
44
+ - **JWT Tokens** - For API clients and stateless authentication (**enabled by default**)
45
+ - **Two-Factor Authentication (2FA)** - TOTP-based second factor (opt-in)
46
+ - **Passkey/WebAuthn** - Passwordless authentication (opt-in)
44
47
 
45
48
  ### Core Features
46
49
 
@@ -93,7 +96,9 @@ https://github.com/lenneTech/nest-server/tree/develop/src/server/modules/better-
93
96
  **Copy from:** Reference implementation
94
97
 
95
98
  **WHY must ALL decorators be re-declared?**
96
- GraphQL schema is built from decorators at compile time. The parent class (`CoreBetterAuthResolver`) is marked as `isAbstract: true`, so its methods are not registered in the schema. You MUST re-declare `@Query`, `@Mutation`, `@Roles`, `@UseGuards` decorators in the child class for the methods to appear in the GraphQL schema.
99
+ GraphQL schema is built from decorators at compile time. The parent class (`CoreBetterAuthResolver`) is marked as `isAbstract: true`, so its methods are not registered in the schema. You MUST re-declare `@Query`, `@Mutation`, `@Roles` decorators in the child class for the methods to appear in the GraphQL schema.
100
+
101
+ **Note:** `@UseGuards(AuthGuard(JWT))` is NOT needed when using `@Roles(S_USER)` or `@Roles(ADMIN)` because `RolesGuard` already extends `AuthGuard(JWT)` internally.
97
102
 
98
103
  ### Step 3: Create BetterAuth Controller
99
104
  **Create:** `src/server/modules/better-auth/better-auth.controller.ts`
@@ -149,22 +154,28 @@ Add `betterAuth` configuration block. See reference for all available options in
149
154
 
150
155
  ## Quick Reference
151
156
 
157
+ **Configuration formats:**
158
+ ```typescript
159
+ betterAuth: true // Enable with all defaults (JWT enabled)
160
+ betterAuth: false // Disable completely
161
+ betterAuth: {} // Same as true
162
+ betterAuth: { ... } // Enable with custom settings
163
+ betterAuth: { enabled: false } // Disable (allows pre-configuration)
164
+ ```
165
+
152
166
  **Default values (used when not configured):**
153
167
 
168
+ - **JWT**: Enabled by default
154
169
  - **Secret**: Falls back to `jwt.secret` → `jwt.refresh.secret` → auto-generated
155
170
  - **Base URL**: `http://localhost:3000`
156
171
  - **Base Path**: `/iam`
157
- - **Passkey Origin**: `http://localhost:3000`
158
- - **Passkey rpId**: `localhost`
159
- - **Passkey rpName**: `Nest Server`
172
+ - **2FA/Passkey**: Disabled (opt-in)
160
173
 
161
174
  To **explicitly disable** Better-Auth:
162
175
 
163
176
  ```typescript
164
177
  const config = {
165
- betterAuth: {
166
- enabled: false,
167
- },
178
+ betterAuth: false, // or betterAuth: { enabled: false }
168
179
  };
169
180
  ```
170
181
 
@@ -330,28 +341,29 @@ const config = {
330
341
  export default {
331
342
  // ... other config
332
343
 
333
- // OPTIONAL: Better-Auth configuration
334
- // Omit entirely for default behavior, or customize as needed:
344
+ // MINIMAL: Just enable BetterAuth (JWT enabled by default)
345
+ betterAuth: true,
346
+
347
+ // OR with customization:
335
348
  betterAuth: {
336
349
  // enabled: true by default - only set to false to disable
337
350
  // secret: auto-generated if not set (see Security section above)
338
351
  // baseUrl: 'http://localhost:3000', // Default
339
352
  // basePath: '/iam', // Default
340
353
 
341
- // JWT Plugin (enabled by default when config block is present)
342
- // Set enabled: false to explicitly disable
354
+ // JWT Plugin - ENABLED BY DEFAULT (no config needed)
355
+ // Only add this block to customize or explicitly disable
343
356
  jwt: {
344
- expiresIn: '15m',
357
+ expiresIn: '30m', // Default: '15m'
358
+ // enabled: false, // Uncomment to disable JWT
345
359
  },
346
360
 
347
- // Two-Factor Authentication (enabled by default when config block is present)
348
- // Set enabled: false to explicitly disable
361
+ // Two-Factor Authentication (opt-in - requires config block)
349
362
  twoFactor: {
350
363
  appName: 'My Application',
351
364
  },
352
365
 
353
- // Passkey/WebAuthn (enabled by default when config block is present)
354
- // Set enabled: false to explicitly disable
366
+ // Passkey/WebAuthn (opt-in - requires config block)
355
367
  passkey: {
356
368
  rpId: 'localhost',
357
369
  rpName: 'My Application',
@@ -515,23 +527,25 @@ Better-Auth provides a rich plugin ecosystem. This module uses a **hybrid approa
515
527
  - **Built-in plugins** (JWT, 2FA, Passkey): Explicitly configured with typed options
516
528
  - **Additional plugins**: Dynamically added via the `plugins` array
517
529
 
518
- ### Built-in Plugins (Explicit Configuration)
530
+ ### Built-in Plugins
519
531
 
520
- These plugins are enabled by default when their config block is present. **All properties have sensible defaults**, so an empty block `{}` is sufficient!
532
+ | Plugin | Default State | Minimal Config to Enable | Default Values |
533
+ | ------------------ | ------------- | ------------------------ | --------------------------------------------------------------------------------- |
534
+ | **JWT** | **ENABLED** | *(none needed)* | `expiresIn: '15m'` |
535
+ | **Two-Factor** | Disabled | `twoFactor: {}` | `appName: 'Nest Server'` |
536
+ | **Passkey** | Disabled | `passkey: {}` | `origin: 'http://localhost:3000'`, `rpId: 'localhost'`, `rpName: 'Nest Server'` |
521
537
 
522
- | Plugin | Minimal Config | Default Values |
523
- | ------------------ | -------------------- | --------------------------------------------------------------------------------- |
524
- | **JWT** | `jwt: {}` | `expiresIn: '15m'` |
525
- | **Two-Factor** | `twoFactor: {}` | `appName: 'Nest Server'` |
526
- | **Passkey** | `passkey: {}` | `origin: 'http://localhost:3000'`, `rpId: 'localhost'`, `rpName: 'Nest Server'` |
538
+ **JWT is enabled by default** - no configuration needed. 2FA and Passkey require explicit configuration.
527
539
 
528
540
  #### Minimal Syntax (Recommended for Development)
529
541
 
530
542
  ```typescript
531
543
  const config = {
544
+ // JWT is enabled automatically with BetterAuth
545
+ betterAuth: true, // or betterAuth: {}
546
+
547
+ // To also enable 2FA and Passkey:
532
548
  betterAuth: {
533
- // Just add empty blocks - all defaults are applied!
534
- jwt: {},
535
549
  twoFactor: {},
536
550
  passkey: {},
537
551
  },
@@ -554,17 +568,20 @@ const config = {
554
568
  };
555
569
  ```
556
570
 
557
- #### Disabling a Plugin
571
+ #### Disabling Plugins
558
572
 
559
573
  ```typescript
560
574
  const config = {
561
575
  betterAuth: {
562
- jwt: { enabled: false }, // Explicitly disable JWT
563
- twoFactor: {}, // 2FA still enabled with defaults
576
+ jwt: false, // Disable JWT (or jwt: { enabled: false })
577
+ twoFactor: {}, // 2FA enabled with defaults
578
+ passkey: { enabled: false }, // Passkey explicitly disabled
564
579
  },
565
580
  };
566
581
  ```
567
582
 
583
+ **Note:** JWT is the only plugin enabled by default. To disable it, use `jwt: false` or `jwt: { enabled: false }`.
584
+
568
585
  ### Dynamic Plugins (plugins Array)
569
586
 
570
587
  For all other Better-Auth plugins, use the `plugins` array. This provides maximum flexibility without requiring updates to this package.
@@ -733,9 +750,9 @@ To explicitly disable Better-Auth:
733
750
 
734
751
  ```typescript
735
752
  const config = {
736
- betterAuth: {
737
- enabled: false,
738
- },
753
+ betterAuth: false, // Simple boolean
754
+ // or
755
+ betterAuth: { enabled: false }, // Allows pre-configuration
739
756
  };
740
757
  ```
741
758
 
@@ -749,10 +766,30 @@ When enabled, Better-Auth exposes the following endpoints at the configured `bas
749
766
  | `/iam/sign-in/email` | POST | Sign in with email/password |
750
767
  | `/iam/sign-out` | GET | Sign out (invalidate session)|
751
768
  | `/iam/session` | GET | Get current session |
769
+ | `/iam/token` | GET | Get fresh JWT token |
752
770
  | `/iam/forgot-password` | POST | Request password reset |
753
771
  | `/iam/reset-password` | POST | Reset password with token |
754
772
  | `/iam/verify-email` | POST | Verify email address |
755
773
 
774
+ ### JWT Token Endpoint
775
+
776
+ The `/iam/token` endpoint returns a fresh JWT token for the current session. Use this when your JWT has expired but your session is still valid.
777
+
778
+ **Request:**
779
+ ```bash
780
+ curl -X GET https://api.example.com/iam/token \
781
+ -H "Cookie: better-auth.session_token=..."
782
+ ```
783
+
784
+ **Response:**
785
+ ```json
786
+ {
787
+ "token": "eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCIsImtpZCI6Ii4uLiJ9..."
788
+ }
789
+ ```
790
+
791
+ **Use case:** Microservice authentication - pass the JWT to other services that verify tokens via JWKS (`/iam/jwks`) without database access.
792
+
756
793
  ### Social Login Endpoints
757
794
 
758
795
  | Endpoint | Method | Description |
@@ -781,12 +818,14 @@ In addition to REST endpoints, Better-Auth provides GraphQL queries and mutation
781
818
 
782
819
  ### Queries
783
820
 
784
- | Query | Arguments | Return Type | Description |
785
- | ------------------------ | --------- | ---------------------------- | ------------------------------- |
786
- | `betterAuthEnabled` | - | `Boolean` | Check if Better-Auth is enabled |
787
- | `betterAuthFeatures` | - | `BetterAuthFeaturesModel` | Get enabled features status |
788
- | `betterAuthSession` | - | `BetterAuthSessionModel` | Get current session (auth req.) |
789
- | `betterAuthListPasskeys` | - | `[BetterAuthPasskeyModel]` | List user's passkeys (auth req.)|
821
+ | Query | Arguments | Return Type | Description |
822
+ | ------------------------ | --------- | ---------------------------- | --------------------------------- |
823
+ | `betterAuthEnabled` | - | `Boolean` | Check if Better-Auth is enabled |
824
+ | `betterAuthFeatures` | - | `BetterAuthFeaturesModel` | Get enabled features status |
825
+ | `betterAuthSession` | - | `BetterAuthSessionModel` | Get current session (auth req.) |
826
+ | `betterAuthToken` | - | `String` | Get fresh JWT token (auth req.) |
827
+ | `betterAuthListPasskeys` | - | `[BetterAuthPasskeyModel]` | List user's passkeys (auth req.) |
828
+ | `betterAuthMigrationStatus` | - | `BetterAuthMigrationStatusModel` | Migration status (admin only) |
790
829
 
791
830
  ### Mutations
792
831
 
@@ -100,7 +100,7 @@ export class BetterAuthRateLimiter {
100
100
  };
101
101
 
102
102
  if (this.config.enabled) {
103
- this.logger.log(`Rate limiting enabled: ${this.config.max} requests per ${this.config.windowSeconds}s`);
103
+ this.logger.debug(`Rate limiting enabled: ${this.config.max} requests per ${this.config.windowSeconds}s`);
104
104
  }
105
105
  }
106
106