nesthub 1.0.3 → 1.2.0-alpha.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 (118) hide show
  1. package/README.md +58 -8
  2. package/dist/auth/README.md +346 -0
  3. package/dist/auth/auth.constants.d.ts +13 -0
  4. package/dist/auth/auth.constants.js +17 -0
  5. package/dist/auth/auth.constants.js.map +1 -0
  6. package/dist/auth/auth.module.d.ts +10 -0
  7. package/dist/auth/auth.module.js +275 -0
  8. package/dist/auth/auth.module.js.map +1 -0
  9. package/dist/auth/controllers/admin.controller.d.ts +13 -0
  10. package/dist/auth/controllers/admin.controller.js +73 -0
  11. package/dist/auth/controllers/admin.controller.js.map +1 -0
  12. package/dist/auth/controllers/auth.controller.d.ts +29 -0
  13. package/dist/auth/controllers/auth.controller.js +258 -0
  14. package/dist/auth/controllers/auth.controller.js.map +1 -0
  15. package/dist/auth/controllers/passkey.controller.d.ts +35 -0
  16. package/dist/auth/controllers/passkey.controller.js +175 -0
  17. package/dist/auth/controllers/passkey.controller.js.map +1 -0
  18. package/dist/auth/controllers/two-factor.controller.d.ts +29 -0
  19. package/dist/auth/controllers/two-factor.controller.js +146 -0
  20. package/dist/auth/controllers/two-factor.controller.js.map +1 -0
  21. package/dist/auth/decorators/current-user.decorator.d.ts +2 -0
  22. package/dist/auth/decorators/current-user.decorator.js +12 -0
  23. package/dist/auth/decorators/current-user.decorator.js.map +1 -0
  24. package/dist/auth/decorators/public.decorator.d.ts +2 -0
  25. package/dist/auth/decorators/public.decorator.js +8 -0
  26. package/dist/auth/decorators/public.decorator.js.map +1 -0
  27. package/dist/auth/decorators/roles.decorator.d.ts +2 -0
  28. package/dist/auth/decorators/roles.decorator.js +8 -0
  29. package/dist/auth/decorators/roles.decorator.js.map +1 -0
  30. package/dist/auth/entities/account.entity.d.ts +20 -0
  31. package/dist/auth/entities/account.entity.js +108 -0
  32. package/dist/auth/entities/account.entity.js.map +1 -0
  33. package/dist/auth/entities/passkey.entity.d.ts +15 -0
  34. package/dist/auth/entities/passkey.entity.js +82 -0
  35. package/dist/auth/entities/passkey.entity.js.map +1 -0
  36. package/dist/auth/entities/token-session.entity.d.ts +14 -0
  37. package/dist/auth/entities/token-session.entity.js +80 -0
  38. package/dist/auth/entities/token-session.entity.js.map +1 -0
  39. package/dist/auth/entities/user.entity.d.ts +25 -0
  40. package/dist/auth/entities/user.entity.js +124 -0
  41. package/dist/auth/entities/user.entity.js.map +1 -0
  42. package/dist/auth/entities/verification.entity.d.ts +11 -0
  43. package/dist/auth/entities/verification.entity.js +62 -0
  44. package/dist/auth/entities/verification.entity.js.map +1 -0
  45. package/dist/auth/guards/auth.guard.d.ts +17 -0
  46. package/dist/auth/guards/auth.guard.js +93 -0
  47. package/dist/auth/guards/auth.guard.js.map +1 -0
  48. package/dist/auth/guards/roles.guard.d.ts +7 -0
  49. package/dist/auth/guards/roles.guard.js +44 -0
  50. package/dist/auth/guards/roles.guard.js.map +1 -0
  51. package/dist/auth/guards/two-factor.guard.d.ts +4 -0
  52. package/dist/auth/guards/two-factor.guard.js +30 -0
  53. package/dist/auth/guards/two-factor.guard.js.map +1 -0
  54. package/dist/auth/index.d.ts +27 -0
  55. package/dist/auth/index.js +57 -0
  56. package/dist/auth/index.js.map +1 -0
  57. package/dist/auth/interfaces.d.ts +281 -0
  58. package/dist/auth/interfaces.js +3 -0
  59. package/dist/auth/interfaces.js.map +1 -0
  60. package/dist/auth/responses.d.ts +173 -0
  61. package/dist/auth/responses.js +679 -0
  62. package/dist/auth/responses.js.map +1 -0
  63. package/dist/auth/services/anonymous.service.d.ts +8 -0
  64. package/dist/auth/services/anonymous.service.js +46 -0
  65. package/dist/auth/services/anonymous.service.js.map +1 -0
  66. package/dist/auth/services/auth.service.d.ts +35 -0
  67. package/dist/auth/services/auth.service.js +492 -0
  68. package/dist/auth/services/auth.service.js.map +1 -0
  69. package/dist/auth/services/magic-link.service.d.ts +18 -0
  70. package/dist/auth/services/magic-link.service.js +110 -0
  71. package/dist/auth/services/magic-link.service.js.map +1 -0
  72. package/dist/auth/services/oauth.service.d.ts +24 -0
  73. package/dist/auth/services/oauth.service.js +178 -0
  74. package/dist/auth/services/oauth.service.js.map +1 -0
  75. package/dist/auth/services/onetap.service.d.ts +9 -0
  76. package/dist/auth/services/onetap.service.js +94 -0
  77. package/dist/auth/services/onetap.service.js.map +1 -0
  78. package/dist/auth/services/otp.service.d.ts +21 -0
  79. package/dist/auth/services/otp.service.js +152 -0
  80. package/dist/auth/services/otp.service.js.map +1 -0
  81. package/dist/auth/services/passkey.service.d.ts +40 -0
  82. package/dist/auth/services/passkey.service.js +132 -0
  83. package/dist/auth/services/passkey.service.js.map +1 -0
  84. package/dist/auth/services/sso.service.d.ts +18 -0
  85. package/dist/auth/services/sso.service.js +125 -0
  86. package/dist/auth/services/sso.service.js.map +1 -0
  87. package/dist/auth/services/token-blacklist.service.d.ts +9 -0
  88. package/dist/auth/services/token-blacklist.service.js +55 -0
  89. package/dist/auth/services/token-blacklist.service.js.map +1 -0
  90. package/dist/auth/services/token.service.d.ts +21 -0
  91. package/dist/auth/services/token.service.js +114 -0
  92. package/dist/auth/services/token.service.js.map +1 -0
  93. package/dist/auth/services/two-factor.service.d.ts +23 -0
  94. package/dist/auth/services/two-factor.service.js +144 -0
  95. package/dist/auth/services/two-factor.service.js.map +1 -0
  96. package/dist/auth/strategies/jwt.strategy.d.ts +17 -0
  97. package/dist/auth/strategies/jwt.strategy.js +39 -0
  98. package/dist/auth/strategies/jwt.strategy.js.map +1 -0
  99. package/dist/auth/types/request.type.d.ts +5 -0
  100. package/dist/auth/types/request.type.js +3 -0
  101. package/dist/auth/types/request.type.js.map +1 -0
  102. package/dist/index.d.ts +2 -0
  103. package/dist/index.js +2 -0
  104. package/dist/index.js.map +1 -1
  105. package/dist/swagger/README.md +53 -0
  106. package/dist/swagger/index.d.ts +2 -0
  107. package/dist/swagger/index.js +6 -0
  108. package/dist/swagger/index.js.map +1 -0
  109. package/dist/swagger/swagger-setup.d.ts +3 -0
  110. package/dist/swagger/swagger-setup.js +21 -0
  111. package/dist/swagger/swagger-setup.js.map +1 -0
  112. package/dist/swagger/swagger.interfaces.d.ts +9 -0
  113. package/dist/swagger/swagger.interfaces.js +3 -0
  114. package/dist/swagger/swagger.interfaces.js.map +1 -0
  115. package/dist/tsconfig.build.tsbuildinfo +1 -1
  116. package/package.json +87 -5
  117. package/src/auth/README.md +346 -0
  118. package/src/swagger/README.md +53 -0
package/README.md CHANGED
@@ -8,15 +8,16 @@ A collection of modular NestJS utility packages. Each module can be imported ind
8
8
  npm install nesthub
9
9
  ```
10
10
 
11
- ## Available modules
11
+ Each sub-package has its own peer dependencies. Install only the modules you need:
12
12
 
13
- | Import path | Description | README |
14
- |---|---|---|
15
- | `nesthub/typeorm` | TypeORM configuration helpers (RDS PostgreSQL, MySQL) | [README](src/typeorm/README.md) |
16
- | `nesthub/cache` | Global cache module with Valkey / Redis backend | [README](src/cache/README.md) |
17
- | `nesthub/queue` | BullMQ config factory for Valkey / Redis backend | [README](src/queue/README.md) |
18
- | `nesthub/notification` | Multi-channel notification module (email, SMS, Firebase, Telegram) with templates, queue, TypeORM persistence | [README](src/notification/README.md) |
19
- | `nesthub/excel` | Export JSON data to Excel (.xlsx)fast, zero boilerplate | [README](src/excel/README.md) |
13
+ | Import path | Install command | Description | README |
14
+ |---|---|---|---|
15
+ | `nesthub/typeorm` | `npm install nesthub @nestjs/typeorm @nestjs/config pg` | TypeORM configuration helpers (RDS PostgreSQL, MySQL) | [README](src/typeorm/README.md) |
16
+ | `nesthub/cache` | `npm install nesthub keyv cacheable` + `@keyv/valkey` or `@keyv/redis` | Global cache module with Valkey / Redis backend | [README](src/cache/README.md) |
17
+ | `nesthub/queue` | `npm install nesthub @nestjs/bullmq bullmq` | BullMQ config factory for Valkey / Redis backend | [README](src/queue/README.md) |
18
+ | `nesthub/notification` | `npm install nesthub` + optional peers (see [README](src/notification/README.md)) | Multi-channel notification module (email, SMS, Firebase, Telegram) with templates, queue, TypeORM persistence | [README](src/notification/README.md) |
19
+ | `nesthub/auth` | `npm install nesthub @nestjs/jwt @nestjs/passport passport passport-jwt bcrypt otplib` | Feature-rich Auth module JWT, OAuth, SSO, 2FA, Passkeys, magic link, OTP, session management, GDPR account deletion | [README](src/auth/README.md) |
20
+ | `nesthub/excel` | `npm install nesthub exceljs` | Export JSON data to Excel (.xlsx) — fast, zero boilerplate | [README](src/excel/README.md) |
20
21
 
21
22
  Click each README link above for detailed usage, environment variables, and options specific to that module.
22
23
 
@@ -24,6 +25,10 @@ Click each README link above for detailed usage, environment variables, and opti
24
25
 
25
26
  ### TypeORM
26
27
 
28
+ ```bash
29
+ npm install nesthub @nestjs/typeorm @nestjs/config pg
30
+ ```
31
+
27
32
  ```typescript
28
33
  import { TypeOrmModule } from '@nestjs/typeorm'
29
34
  import { ConfigService } from '@nestjs/config'
@@ -38,6 +43,10 @@ TypeOrmModule.forRootAsync({
38
43
 
39
44
  ### Cache
40
45
 
46
+ ```bash
47
+ npm install nesthub keyv cacheable @keyv/valkey
48
+ ```
49
+
41
50
  ```typescript
42
51
  import { CacheModule } from 'nesthub/cache'
43
52
 
@@ -49,6 +58,10 @@ export class AppModule {}
49
58
 
50
59
  ### Queue
51
60
 
61
+ ```bash
62
+ npm install nesthub @nestjs/bullmq bullmq
63
+ ```
64
+
52
65
  ```typescript
53
66
  import { BullModule } from '@nestjs/bullmq'
54
67
  import { configBullMQ } from 'nesthub/queue'
@@ -61,6 +74,11 @@ BullModule.forRootAsync({
61
74
 
62
75
  ### Notification
63
76
 
77
+ ```bash
78
+ npm install nesthub
79
+ # Optional: npm install nodemailer twilio firebase-admin handlebars @nestjs/bullmq bullmq @nestjs/typeorm typeorm
80
+ ```
81
+
64
82
  ```typescript
65
83
  import { Module } from '@nestjs/common'
66
84
  import { NotificationModule } from 'nesthub/notification'
@@ -81,8 +99,40 @@ import { NotificationModule } from 'nesthub/notification'
81
99
  export class AppModule {}
82
100
  ```
83
101
 
102
+ ### Auth
103
+
104
+ ```bash
105
+ npm install @nestjs/jwt @nestjs/passport passport passport-jwt bcrypt otplib
106
+ ```
107
+
108
+ ```typescript
109
+ import { Module } from '@nestjs/common'
110
+ import { AuthModule } from 'nesthub/auth'
111
+
112
+ @Module({
113
+ imports: [
114
+ AuthModule.forRoot({
115
+ security: { jwtSecret: process.env.JWT_SECRET },
116
+ oauth: {
117
+ google: {
118
+ clientId: process.env.GOOGLE_CLIENT_ID!,
119
+ clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
120
+ },
121
+ },
122
+ twoFactor: { enabled: true, methods: ['totp', 'email'] },
123
+ passkey: { enabled: true, relyingPartyId: 'example.com', origin: 'https://example.com' },
124
+ }),
125
+ ],
126
+ })
127
+ export class AppModule {}
128
+ ```
129
+
84
130
  ### Excel
85
131
 
132
+ ```bash
133
+ npm install nesthub exceljs
134
+ ```
135
+
86
136
  ```typescript
87
137
  import { exportToBuffer, exportToFile, exportToResponse } from 'nesthub/excel'
88
138
 
@@ -0,0 +1,346 @@
1
+ # NestHub Auth Module
2
+
3
+ All-in-one authentication module for NestJS, inspired by Better Auth. Supports multiple authentication mechanisms with enterprise-grade security.
4
+
5
+ ## Features
6
+
7
+ - **Credentials**: Email/username + password login
8
+ - **OAuth**: Google, GitHub, Facebook, Apple, Microsoft, Discord, and custom providers
9
+ - **Two-Factor Auth (2FA)**: TOTP-based with backup codes
10
+ - **Anonymous**: Anonymous sessions convertible to permanent accounts
11
+ - **Magic Link**: Passwordless email login
12
+ - **OTP**: One-time password via email/phone
13
+ - **Passkey**: WebAuthn/FIDO2 passkey authentication
14
+ - **OneTap**: Google & Apple OneTap sign-in
15
+ - **SSO**: SAML & OpenID Connect support
16
+ - **Session Management**: Stateless JWT with refresh tokens, multi-device tracking, per-device logout (like Telegram)
17
+ - **Security**: Password hashing (bcrypt), rate limiting, token versioning, token blacklist via Redis/Valkey
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ npm install @nestjs/jwt @nestjs/passport passport passport-jwt bcrypt otplib
23
+ ```
24
+
25
+ ## Quick Start
26
+
27
+ ```typescript
28
+ import { Module } from '@nestjs/common';
29
+ import { TypeOrmModule } from '@nestjs/typeorm';
30
+ import { AuthModule } from 'nesthub/auth';
31
+
32
+ @Module({
33
+ imports: [
34
+ TypeOrmModule.forRoot({ ... }),
35
+ AuthModule.forRoot({
36
+ credentials: { enabled: true, allowRegistration: true },
37
+ security: {
38
+ jwtSecret: process.env.JWT_SECRET,
39
+ passwordHashRounds: 12,
40
+ maxSessions: { enabled: true, maxPerUser: 5 },
41
+ },
42
+ oauth: {
43
+ google: {
44
+ enabled: true,
45
+ clientId: process.env.GOOGLE_CLIENT_ID,
46
+ clientSecret: process.env.GOOGLE_CLIENT_SECRET,
47
+ },
48
+ github: {
49
+ enabled: false,
50
+ clientId: process.env.GITHUB_CLIENT_ID,
51
+ clientSecret: process.env.GITHUB_CLIENT_SECRET,
52
+ },
53
+ },
54
+ twoFactor: {
55
+ enabled: true,
56
+ issuer: 'MyApp',
57
+ },
58
+ }),
59
+ ],
60
+ })
61
+ export class AppModule {}
62
+ ```
63
+
64
+ ## Configuration via .env
65
+
66
+ ```env
67
+ # JWT
68
+ JWT_SECRET=your-jwt-secret
69
+ JWT_EXPIRES_IN=15m
70
+
71
+ # OAuth Providers
72
+ GOOGLE_CLIENT_ID=xxx
73
+ GOOGLE_CLIENT_SECRET=xxx
74
+ GITHUB_CLIENT_ID=xxx
75
+ GITHUB_CLIENT_SECRET=xxx
76
+ FACEBOOK_CLIENT_ID=xxx
77
+ FACEBOOK_CLIENT_SECRET=xxx
78
+ APPLE_CLIENT_ID=xxx
79
+ APPLE_CLIENT_SECRET=xxx
80
+ MICROSOFT_CLIENT_ID=xxx
81
+ MICROSOFT_CLIENT_SECRET=xxx
82
+ DISCORD_CLIENT_ID=xxx
83
+ DISCORD_CLIENT_SECRET=xxx
84
+
85
+ # App
86
+ APP_URL=http://localhost:3000
87
+ ```
88
+
89
+ ## Usage
90
+
91
+ ### Register
92
+
93
+ ```typescript
94
+ POST /auth/register
95
+ { "email": "user@example.com", "password": "secure123", "name": "User", "deviceName": "iPhone 15" }
96
+ ```
97
+
98
+ ### Login
99
+
100
+ ```typescript
101
+ POST /auth/login
102
+ { "identifier": "user@example.com", "password": "secure123", "deviceName": "Chrome on Mac" }
103
+ ```
104
+
105
+ ### Response Structure
106
+
107
+ All endpoints return a consistent response format:
108
+
109
+ ```typescript
110
+ // Successful login/register
111
+ {
112
+ "user": {
113
+ "id": "uuid",
114
+ "email": "user@example.com",
115
+ "emailVerified": false,
116
+ "phone": null,
117
+ "name": "User",
118
+ "image": null,
119
+ "roles": ["user"],
120
+ "isAnonymous": false,
121
+ "twoFactorEnabled": false,
122
+ "twoFactorVerified": false
123
+ },
124
+ "accessToken": "eyJhbGci...",
125
+ "refreshToken": "eyJhbGci..."
126
+ }
127
+
128
+ // When 2FA is required
129
+ {
130
+ "user": { ... },
131
+ "requiresTwoFactor": true,
132
+ "accessToken": ""
133
+ }
134
+ ```
135
+
136
+ ### Session Management (like Telegram)
137
+
138
+ List all active devices/sessions:
139
+
140
+ ```typescript
141
+ GET /auth/sessions
142
+ Authorization: Bearer <accessToken>
143
+
144
+ // Response
145
+ [
146
+ {
147
+ "id": "uuid",
148
+ "userId": "uuid",
149
+ "jti": "hex-token-id",
150
+ "ipAddress": "192.168.1.1",
151
+ "userAgent": "Mozilla/5.0 ...",
152
+ "deviceName": "Chrome on Mac",
153
+ "expiresAt": "2026-07-20T00:00:00Z",
154
+ "createdAt": "2026-06-20T00:00:00Z"
155
+ }
156
+ ]
157
+ ```
158
+
159
+ Revoke a specific session (logout that device without affecting others):
160
+
161
+ ```typescript
162
+ DELETE /auth/sessions/:id
163
+ Authorization: Bearer <accessToken>
164
+
165
+ // Response
166
+ { "message": "Session revoked" }
167
+ ```
168
+
169
+ Logout current session:
170
+
171
+ ```typescript
172
+ POST /auth/logout
173
+ Authorization: Bearer <accessToken>
174
+
175
+ // Optional: pass jti to revoke a specific token
176
+ { "jti": "hex-token-id" }
177
+ ```
178
+
179
+ Logout all sessions (increments tokenVersion, invalidating all existing tokens):
180
+
181
+ ```typescript
182
+ POST /auth/logout-all
183
+ Authorization: Bearer <accessToken>
184
+ ```
185
+
186
+ ### Magic Link
187
+
188
+ ```typescript
189
+ POST /auth/magic-link/send
190
+ { "email": "user@example.com" }
191
+
192
+ POST /auth/magic-link/verify
193
+ { "token": "..." }
194
+ ```
195
+
196
+ ### OTP
197
+
198
+ ```typescript
199
+ POST /auth/otp/send
200
+ { "identifier": "user@example.com", "purpose": "login" }
201
+
202
+ POST /auth/otp/verify
203
+ { "identifier": "user@example.com", "code": "123456", "purpose": "login" }
204
+ ```
205
+
206
+ ### 2FA
207
+
208
+ ```typescript
209
+ GET /auth/2fa/setup # Get TOTP secret + QR code URL
210
+ POST /auth/2fa/enable # { "secret": "...", "code": "123456" }
211
+ POST /auth/2fa/verify # { "code": "123456" }
212
+ POST /auth/2fa/disable
213
+ POST /auth/2fa/backup-codes # Generate new backup codes
214
+ ```
215
+
216
+ ### Passkey (WebAuthn)
217
+
218
+ ```typescript
219
+ POST /auth/passkeys/register/initiate
220
+ POST /auth/passkeys/register/complete
221
+ POST /auth/passkeys/authenticate/initiate
222
+ POST /auth/passkeys/authenticate/complete
223
+ GET /auth/passkeys
224
+ DELETE /auth/passkeys/:id
225
+ ```
226
+
227
+ ### Anonymous
228
+
229
+ ```typescript
230
+ POST /auth/anonymous
231
+ POST /auth/anonymous/convert
232
+ { "email": "user@example.com", "password": "secure123", "name": "User" }
233
+ ```
234
+
235
+ ### OAuth
236
+
237
+ ```typescript
238
+ GET /auth/oauth/providers
239
+ POST /auth/oauth/:provider/callback
240
+ { "code": "...", "redirectUri": "..." }
241
+ ```
242
+
243
+ ### OneTap
244
+
245
+ ```typescript
246
+ POST /auth/onetap/google { "idToken": "..." }
247
+ POST /auth/onetap/apple { "idToken": "..." }
248
+ ```
249
+
250
+ ### SSO
251
+
252
+ ```typescript
253
+ GET /auth/sso/providers
254
+ POST /auth/sso/:provider/callback
255
+ { "attributes": { "email": "...", "name": "..." } }
256
+ ```
257
+
258
+ ### Profile & Account
259
+
260
+ ```typescript
261
+ GET /auth/profile
262
+ POST /auth/profile { "name": "...", "image": "..." }
263
+ POST /auth/change-password { "currentPassword": "...", "newPassword": "..." }
264
+ DELETE /auth/account # GDPR-compliant account deletion (anonymizes PII)
265
+ ```
266
+
267
+ ## API Reference
268
+
269
+ ### AuthModule.forRoot(options)
270
+
271
+ | Option | Type | Default | Description |
272
+ |--------|------|---------|-------------|
273
+ | `credentials` | `CredentialsConfig` | `{ enabled: true, allowRegistration: true }` | Email/phone + password login & registration |
274
+ | `oauth` | `ProviderConfig` | - | OAuth provider configs (each provider has `enabled` flag) |
275
+ | `sso` | `SSOProviderConfig[]` | - | SSO provider configs (each provider has `enabled` flag) |
276
+ | `twoFactor` | `TwoFactorConfig` | `{ enabled: true }` | 2FA configuration |
277
+ | `passkey` | `PasskeyConfig` | `{ enabled: false }` | WebAuthn config |
278
+ | `anonymous` | `AnonymousConfig` | `{ enabled: true }` | Anonymous auth config |
279
+ | `magicLink` | `MagicLinkConfig` | `{ enabled: false }` | Magic link config |
280
+ | `otp` | `OtpConfig` | `{ enabled: false }` | OTP config |
281
+ | `onelink` | `OnelinkConfig` | `{ enabled: false }` | Google & Apple OneTap sign-in |
282
+ | `security` | `SecurityConfig` | (see below) | Security settings |
283
+ | `email` | `EmailChannelConfig` | - | Email notification config |
284
+ | `override` | `OverrideConfig` | - | Override entities/services/controllers |
285
+
286
+ ### Security Defaults
287
+
288
+ ```typescript
289
+ {
290
+ passwordHashRounds: 12,
291
+ jwtExpiresIn: '15m',
292
+ refreshTokenExpiresIn: '7d',
293
+ rateLimit: { enabled: true, maxAttempts: 5, windowMs: 900000 },
294
+ requireEmailVerification: false,
295
+ maxSessions: { enabled: false, maxPerUser: 5 },
296
+ }
297
+ ```
298
+
299
+ ### Override Custom Classes
300
+
301
+ You can extend and override any entity, service, or controller:
302
+
303
+ ```typescript
304
+ import { AuthService, AuthController, User } from 'nesthub/auth';
305
+
306
+ class CustomUser extends User { /* extra columns */ }
307
+ class CustomAuthService extends AuthService { /* overridden methods */ }
308
+ class CustomAuthController extends AuthController { /* overridden endpoints */ }
309
+
310
+ AuthModule.forRoot({
311
+ override: {
312
+ entities: { user: CustomUser },
313
+ services: { auth: CustomAuthService },
314
+ controllers: { auth: CustomAuthController },
315
+ },
316
+ })
317
+ ```
318
+
319
+ ## Guards & Decorators
320
+
321
+ ```typescript
322
+ import { AuthGuard, RolesGuard } from 'nesthub/auth';
323
+ import { Public, CurrentUser, Roles } from 'nesthub/auth';
324
+
325
+ @UseGuards(AuthGuard)
326
+ @Get('profile')
327
+ getProfile(@CurrentUser() user: AuthenticatedUser) {}
328
+
329
+ @Public()
330
+ @Get('public-route')
331
+ publicEndpoint() {}
332
+
333
+ @UseGuards(AuthGuard, RolesGuard)
334
+ @Roles('admin')
335
+ @Get('admin')
336
+ adminOnly() {}
337
+ ```
338
+
339
+ ## Dependencies
340
+
341
+ Optional peer dependencies:
342
+ - `@nestjs/jwt` - JWT token handling
343
+ - `@nestjs/passport` + `passport` + `passport-jwt` - Passport strategies
344
+ - `bcrypt` - Password hashing
345
+ - `otplib` - TOTP for 2FA
346
+ - `@nestjs/cache-manager` or `nesthub/cache` (Redis/Valkey) - Token blacklist (recommended for production)
@@ -0,0 +1,13 @@
1
+ export declare const AUTH_OPTIONS = "AUTH_OPTIONS";
2
+ export declare const AUTH_PREFIX = "auth";
3
+ export declare const AUTH_USER_SERVICE = "AUTH_USER_SERVICE";
4
+ export declare const AUTH_SESSION_SERVICE = "AUTH_SESSION_SERVICE";
5
+ export declare const AUTH_OAUTH_PROVIDERS = "AUTH_OAUTH_PROVIDERS";
6
+ export declare const AUTH_SSO_PROVIDERS = "AUTH_SSO_PROVIDERS";
7
+ export declare const AUTH_PASSKEY_SERVICE = "AUTH_PASSKEY_SERVICE";
8
+ export declare const AUTH_EMAIL_SERVICE = "AUTH_EMAIL_SERVICE";
9
+ export declare const PASSWORD_RESET_PREFIX = "auth:pwdreset:";
10
+ export declare const MAGIC_LINK_PREFIX = "auth:magiclink:";
11
+ export declare const OTP_PREFIX = "auth:otp:";
12
+ export declare const VERIFY_EMAIL_PREFIX = "auth:verify:";
13
+ export declare const AUTH_CACHE_NAMESPACE = "nesthub:auth";
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AUTH_CACHE_NAMESPACE = exports.VERIFY_EMAIL_PREFIX = exports.OTP_PREFIX = exports.MAGIC_LINK_PREFIX = exports.PASSWORD_RESET_PREFIX = exports.AUTH_EMAIL_SERVICE = exports.AUTH_PASSKEY_SERVICE = exports.AUTH_SSO_PROVIDERS = exports.AUTH_OAUTH_PROVIDERS = exports.AUTH_SESSION_SERVICE = exports.AUTH_USER_SERVICE = exports.AUTH_PREFIX = exports.AUTH_OPTIONS = void 0;
4
+ exports.AUTH_OPTIONS = 'AUTH_OPTIONS';
5
+ exports.AUTH_PREFIX = 'auth';
6
+ exports.AUTH_USER_SERVICE = 'AUTH_USER_SERVICE';
7
+ exports.AUTH_SESSION_SERVICE = 'AUTH_SESSION_SERVICE';
8
+ exports.AUTH_OAUTH_PROVIDERS = 'AUTH_OAUTH_PROVIDERS';
9
+ exports.AUTH_SSO_PROVIDERS = 'AUTH_SSO_PROVIDERS';
10
+ exports.AUTH_PASSKEY_SERVICE = 'AUTH_PASSKEY_SERVICE';
11
+ exports.AUTH_EMAIL_SERVICE = 'AUTH_EMAIL_SERVICE';
12
+ exports.PASSWORD_RESET_PREFIX = 'auth:pwdreset:';
13
+ exports.MAGIC_LINK_PREFIX = 'auth:magiclink:';
14
+ exports.OTP_PREFIX = 'auth:otp:';
15
+ exports.VERIFY_EMAIL_PREFIX = 'auth:verify:';
16
+ exports.AUTH_CACHE_NAMESPACE = 'nesthub:auth';
17
+ //# sourceMappingURL=auth.constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.constants.js","sourceRoot":"","sources":["../../src/auth/auth.constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,YAAY,GAAG,cAAc,CAAC;AAC9B,QAAA,WAAW,GAAG,MAAM,CAAC;AAErB,QAAA,iBAAiB,GAAG,mBAAmB,CAAC;AAExC,QAAA,oBAAoB,GAAG,sBAAsB,CAAC;AAE9C,QAAA,oBAAoB,GAAG,sBAAsB,CAAC;AAE9C,QAAA,kBAAkB,GAAG,oBAAoB,CAAC;AAE1C,QAAA,oBAAoB,GAAG,sBAAsB,CAAC;AAE9C,QAAA,kBAAkB,GAAG,oBAAoB,CAAC;AAE1C,QAAA,qBAAqB,GAAG,gBAAgB,CAAC;AACzC,QAAA,iBAAiB,GAAG,iBAAiB,CAAC;AACtC,QAAA,UAAU,GAAG,WAAW,CAAC;AACzB,QAAA,mBAAmB,GAAG,cAAc,CAAC;AAErC,QAAA,oBAAoB,GAAG,cAAc,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { DynamicModule, Type, ForwardReference } from '@nestjs/common';
2
+ import type { AuthModuleOptions } from './interfaces';
3
+ export declare class AuthModule {
4
+ static forRoot(options?: AuthModuleOptions): DynamicModule;
5
+ static forRootAsync(options: {
6
+ useFactory: (...args: any[]) => AuthModuleOptions | Promise<AuthModuleOptions>;
7
+ inject?: (string | symbol | Type<any>)[];
8
+ imports?: (DynamicModule | Type<any> | Promise<DynamicModule> | ForwardReference)[];
9
+ }): DynamicModule;
10
+ }