@ackplus/nest-auth 1.1.15 → 1.1.16

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 (28) hide show
  1. package/README.md +82 -6
  2. package/package.json +1 -1
  3. package/src/lib/admin-console/static/index.html +4736 -432
  4. package/src/lib/auth/auth.module.d.ts.map +1 -1
  5. package/src/lib/auth/auth.module.js +2 -0
  6. package/src/lib/auth/controllers/auth.controller.d.ts +1 -0
  7. package/src/lib/auth/controllers/auth.controller.d.ts.map +1 -1
  8. package/src/lib/auth/controllers/auth.controller.js +19 -2
  9. package/src/lib/auth/dto/requests/verify-2fa.request.dto.d.ts +1 -0
  10. package/src/lib/auth/dto/requests/verify-2fa.request.dto.d.ts.map +1 -1
  11. package/src/lib/auth/dto/requests/verify-2fa.request.dto.js +8 -0
  12. package/src/lib/auth/entities/trusted-device.entity.d.ts +13 -0
  13. package/src/lib/auth/entities/trusted-device.entity.d.ts.map +1 -0
  14. package/src/lib/auth/entities/trusted-device.entity.js +51 -0
  15. package/src/lib/auth/index.d.ts +1 -0
  16. package/src/lib/auth/index.d.ts.map +1 -1
  17. package/src/lib/auth/index.js +1 -0
  18. package/src/lib/auth/services/auth.service.d.ts +1 -0
  19. package/src/lib/auth/services/auth.service.d.ts.map +1 -1
  20. package/src/lib/auth/services/auth.service.js +29 -1
  21. package/src/lib/auth/services/mfa.service.d.ts +5 -1
  22. package/src/lib/auth/services/mfa.service.d.ts.map +1 -1
  23. package/src/lib/auth/services/mfa.service.js +40 -1
  24. package/src/lib/auth.constants.d.ts +1 -0
  25. package/src/lib/auth.constants.d.ts.map +1 -1
  26. package/src/lib/auth.constants.js +2 -1
  27. package/src/lib/core/interfaces/mfa-options.interface.d.ts +2 -0
  28. package/src/lib/core/interfaces/mfa-options.interface.d.ts.map +1 -1
package/README.md CHANGED
@@ -1,11 +1,87 @@
1
- # nest-auth
1
+ # @ackplus/nest-auth
2
2
 
3
- This library was generated with [Nx](https://nx.dev).
3
+ A comprehensive authentication and authorization module for NestJS applications, featuring:
4
4
 
5
- ## Building
5
+ - **Multi-tenant support** out of the box
6
+ - **Role-Based Access Control (RBAC)**
7
+ - **Session Management** with secure cookie or header-based tokens
8
+ - **Two-Factor Authentication (2FA)** (TOTP, SMS, Email)
9
+ - **Social Login** (Google, Facebook, Apple, GitHub)
10
+ - **Admin Console** UI for managing users and roles
11
+ - **Mobile-ready** API design
6
12
 
7
- Run `nx build nest-auth` to build the library.
13
+ ## Installation
8
14
 
9
- ## Running unit tests
15
+ ```bash
16
+ npm install @ackplus/nest-auth
17
+ ```
10
18
 
11
- Run `nx test nest-auth` to execute the unit tests via [Jest](https://jestjs.io).
19
+ ## Configuration
20
+
21
+ Import `NestAuthModule` in your `AppModule`. You can use `forRoot` or `forRootAsync`.
22
+
23
+ ```typescript
24
+ import { NestAuthModule } from '@ackplus/nest-auth';
25
+
26
+ @Module({
27
+ imports: [
28
+ NestAuthModule.forRootAsync({
29
+ useFactory: (configService: ConfigService) => ({
30
+ appName: 'My App',
31
+ jwt: {
32
+ secret: configService.get('JWT_SECRET'),
33
+ accessTokenExpiresIn: '15m',
34
+ refreshTokenExpiresIn: '7d',
35
+ },
36
+ mfa: {
37
+ enabled: true,
38
+ methods: ['totp', 'email'],
39
+ // Trusted device configuration
40
+ trustedDeviceDuration: '30d', // Duration to trust a device
41
+ trustDeviceStorageName: 'nest_auth_device_trust', // Cookie/Header name
42
+ },
43
+ // ... other options
44
+ }),
45
+ inject: [ConfigService],
46
+ }),
47
+ ],
48
+ })
49
+ export class AppModule {}
50
+ ```
51
+
52
+ ## Features
53
+
54
+ ### Two-Factor Authentication (2FA)
55
+
56
+ The library supports TOTP (Authenticator apps), SMS, and Email-based 2FA.
57
+
58
+ #### Trusted Devices ("Remember Me")
59
+
60
+ Users can choose to trust their device during 2FA verification to skip 2FA on subsequent logins for a configured duration.
61
+
62
+ **Web Flow (Cookies):**
63
+ 1. Login triggers 2FA (`isRequiresMfa: true`).
64
+ 2. Call `/auth/verify-2fa` with `rememberDevice: true`.
65
+ 3. Server sets a `nest_auth_device_trust` (or configured name) HTTP-only cookie.
66
+ 4. Subsequent logins from the same browser will automatically skip 2FA.
67
+
68
+ **Mobile Flow (Headers):**
69
+ 1. Login triggers 2FA (`isRequiresMfa: true`).
70
+ 2. Call `/auth/verify-2fa` with `rememberDevice: true`.
71
+ 3. Response body includes `trustToken`.
72
+ 4. Store `trustToken` securely (e.g., Keychain/Keystore).
73
+ 5. For subsequent logins, send the token in the request header:
74
+ ```
75
+ x-nest-auth-trust-token: <your-trust-token>
76
+ ```
77
+ *Note: The header name defaults to `nest_auth_device_trust` or whatever you configured in `trustDeviceStorageName`.*
78
+
79
+ ### Admin Console
80
+
81
+ The library includes an embedded Admin Console UI for managing users, roles, and settings.
82
+ Access it at `/auth/admin`.
83
+
84
+ ## API Documentation
85
+
86
+ The API documentation is available via Swagger UI at `/api` (if configured in your main application).
87
+ You can also download the OpenAPI specification JSON from the Admin Console or the Swagger UI.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ackplus/nest-auth",
3
- "version": "1.1.15",
3
+ "version": "1.1.16",
4
4
  "type": "commonjs",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",