@lenne.tech/nest-server 11.21.3 → 11.22.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.
- package/.claude/rules/architecture.md +79 -0
- package/.claude/rules/better-auth.md +262 -0
- package/.claude/rules/configurable-features.md +308 -0
- package/.claude/rules/core-modules.md +205 -0
- package/.claude/rules/framework-compatibility.md +79 -0
- package/.claude/rules/migration-guides.md +149 -0
- package/.claude/rules/module-deprecation.md +214 -0
- package/.claude/rules/module-inheritance.md +97 -0
- package/.claude/rules/package-management.md +112 -0
- package/.claude/rules/role-system.md +146 -0
- package/.claude/rules/testing.md +120 -0
- package/.claude/rules/versioning.md +53 -0
- package/CLAUDE.md +174 -0
- package/FRAMEWORK-API.md +231 -0
- package/dist/core/common/interfaces/server-options.interface.d.ts +10 -0
- package/dist/core/modules/error-code/error-code.module.js.map +1 -1
- package/dist/core.module.d.ts +3 -3
- package/dist/core.module.js +17 -4
- package/dist/core.module.js.map +1 -1
- package/dist/server/modules/file/file-info.model.d.ts +1 -5
- package/dist/server/modules/user/user.model.d.ts +1 -5
- package/dist/server/server.module.js +6 -6
- package/dist/server/server.module.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/docs/REQUEST-LIFECYCLE.md +1256 -0
- package/docs/error-codes.md +446 -0
- package/migration-guides/11.10.x-to-11.11.x.md +266 -0
- package/migration-guides/11.11.x-to-11.12.x.md +323 -0
- package/migration-guides/11.12.x-to-11.13.0.md +612 -0
- package/migration-guides/11.13.x-to-11.14.0.md +348 -0
- package/migration-guides/11.14.x-to-11.15.0.md +262 -0
- package/migration-guides/11.15.0-to-11.15.3.md +118 -0
- package/migration-guides/11.15.x-to-11.16.0.md +497 -0
- package/migration-guides/11.16.x-to-11.17.0.md +130 -0
- package/migration-guides/11.17.x-to-11.18.0.md +393 -0
- package/migration-guides/11.18.x-to-11.19.0.md +151 -0
- package/migration-guides/11.19.x-to-11.20.0.md +170 -0
- package/migration-guides/11.20.x-to-11.21.0.md +216 -0
- package/migration-guides/11.21.0-to-11.21.1.md +194 -0
- package/migration-guides/11.21.1-to-11.21.2.md +114 -0
- package/migration-guides/11.21.2-to-11.21.3.md +175 -0
- package/migration-guides/11.21.x-to-11.22.0.md +224 -0
- package/migration-guides/11.22.0-to-11.22.1.md +105 -0
- package/migration-guides/11.3.x-to-11.4.x.md +233 -0
- package/migration-guides/11.6.x-to-11.7.x.md +394 -0
- package/migration-guides/11.7.x-to-11.8.x.md +318 -0
- package/migration-guides/11.8.x-to-11.9.x.md +322 -0
- package/migration-guides/11.9.x-to-11.10.x.md +571 -0
- package/migration-guides/TEMPLATE.md +113 -0
- package/package.json +25 -18
- package/src/core/common/interfaces/server-options.interface.ts +83 -16
- package/src/core/modules/better-auth/CUSTOMIZATION.md +24 -17
- package/src/core/modules/better-auth/INTEGRATION-CHECKLIST.md +5 -5
- package/src/core/modules/error-code/INTEGRATION-CHECKLIST.md +42 -12
- package/src/core/modules/error-code/error-code.module.ts +4 -9
- package/src/core.module.ts +52 -10
- package/src/server/server.module.ts +7 -9
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
# Migration Guide: 11.3.x → 11.4.x
|
|
2
|
+
|
|
3
|
+
## TL;DR
|
|
4
|
+
|
|
5
|
+
**Not using `@nodepit/migrate-state-store-mongodb`?**
|
|
6
|
+
```bash
|
|
7
|
+
npm install @lenne.tech/nest-server@11.4.x
|
|
8
|
+
npm run build && npm test # Done! No breaking changes.
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
**Using `@nodepit/migrate-state-store-mongodb`?** Follow the migration steps below to switch to the built-in system.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Overview
|
|
16
|
+
|
|
17
|
+
| Category | Details |
|
|
18
|
+
|----------|---------|
|
|
19
|
+
| **Breaking Changes** | None (backward compatible) |
|
|
20
|
+
| **New Features** | Built-in migration CLI, MongoStateStore, helper functions |
|
|
21
|
+
| **Bugfixes** | Various MapAndValidatePipe improvements (11.4.2-11.4.5) |
|
|
22
|
+
| **Migration Effort** | ~5 min (no @nodepit) / ~15 min (with @nodepit migration) |
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Prerequisites
|
|
27
|
+
|
|
28
|
+
### ts-node (Required for TypeScript migrations)
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npm install --save-dev ts-node
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## What's New in 11.4.x
|
|
37
|
+
|
|
38
|
+
### 1. Built-in Migration CLI
|
|
39
|
+
|
|
40
|
+
No external `migrate` package required - CLI included in nest-server:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npx migrate --help
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### 2. Migration Helper Functions
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
import { getDb, uploadFileToGridFS, createMigrationStore } from '@lenne.tech/nest-server';
|
|
50
|
+
|
|
51
|
+
const db = await getDb('mongodb://localhost/mydb');
|
|
52
|
+
const fileId = await uploadFileToGridFS('mongodb://localhost/mydb', './assets/logo.png');
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### 3. MongoStateStore
|
|
56
|
+
|
|
57
|
+
Drop-in replacement for `@nodepit/migrate-state-store-mongodb` with MongoDB 7.x support and cluster locking.
|
|
58
|
+
|
|
59
|
+
### 4. S_VERIFIED System Role (11.4.8)
|
|
60
|
+
|
|
61
|
+
New system role for checking user verification status:
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
@Roles(RoleEnum.S_VERIFIED) // Requires verified user
|
|
65
|
+
async someMethod() { }
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Checks: `user.verified || user.verifiedAt || user.emailVerified`
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## Migration from @nodepit
|
|
73
|
+
|
|
74
|
+
### Step 1: Remove Old Packages
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
npm uninstall migrate @nodepit/migrate-state-store-mongodb ts-migrate-mongoose
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Step 2: Update nest-server
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
npm install @lenne.tech/nest-server@11.4.x
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Step 3: Update `migrations-utils/migrate.js`
|
|
87
|
+
|
|
88
|
+
**Before:**
|
|
89
|
+
```javascript
|
|
90
|
+
import config from '../src/config.env';
|
|
91
|
+
const { MongoStateStore } = require('@nodepit/migrate-state-store-mongodb');
|
|
92
|
+
|
|
93
|
+
module.exports = class MyMongoStateStore extends MongoStateStore {
|
|
94
|
+
constructor() {
|
|
95
|
+
super({ uri: config.mongoose.uri, collectionName: 'migrations' });
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
**After:**
|
|
101
|
+
```javascript
|
|
102
|
+
const { createMigrationStore } = require('@lenne.tech/nest-server');
|
|
103
|
+
const config = require('../src/config.env');
|
|
104
|
+
|
|
105
|
+
module.exports = createMigrationStore(
|
|
106
|
+
config.default.mongoose.uri,
|
|
107
|
+
'migrations'
|
|
108
|
+
);
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Step 4: Update `migrations-utils/db.ts`
|
|
112
|
+
|
|
113
|
+
**Before:**
|
|
114
|
+
```typescript
|
|
115
|
+
import { GridFSBucket, MongoClient, ObjectId } from 'mongodb';
|
|
116
|
+
import config from '../src/config.env';
|
|
117
|
+
|
|
118
|
+
const MONGO_URL = config.mongoose.uri;
|
|
119
|
+
|
|
120
|
+
export const getDb = async () => {
|
|
121
|
+
const client: MongoClient = await MongoClient.connect(MONGO_URL);
|
|
122
|
+
return client.db();
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export const uploadFile = async (relativePath, options?) => {
|
|
126
|
+
// ... custom implementation
|
|
127
|
+
};
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
**After:**
|
|
131
|
+
```typescript
|
|
132
|
+
/**
|
|
133
|
+
* Legacy compatibility layer - allows existing migrations to work unchanged
|
|
134
|
+
*/
|
|
135
|
+
import {
|
|
136
|
+
createMigrationStore,
|
|
137
|
+
getDb as nestServerGetDb,
|
|
138
|
+
uploadFileToGridFS,
|
|
139
|
+
} from '@lenne.tech/nest-server';
|
|
140
|
+
import config from '../src/config.env';
|
|
141
|
+
|
|
142
|
+
export { createMigrationStore, uploadFileToGridFS };
|
|
143
|
+
|
|
144
|
+
// Wrapper: existing migrations call getDb() without parameters
|
|
145
|
+
export const getDb = async () => nestServerGetDb(config.mongoose.uri);
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Step 5: Delete Obsolete Files
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
rm migrations-utils/template.ts migrations-utils/ts-compiler.js
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Step 6: Update package.json Scripts
|
|
155
|
+
|
|
156
|
+
**Key changes:**
|
|
157
|
+
- Command (`up`, `down`, `create`) comes **first**, then options
|
|
158
|
+
- Use nest-server paths for template and compiler
|
|
159
|
+
|
|
160
|
+
```json
|
|
161
|
+
{
|
|
162
|
+
"scripts": {
|
|
163
|
+
"migrate:create": "f() { migrate create \"$1\" --template-file ./node_modules/@lenne.tech/nest-server/dist/core/modules/migrate/templates/migration-project.template.ts --migrations-dir ./migrations --compiler ts:./node_modules/@lenne.tech/nest-server/dist/core/modules/migrate/helpers/ts-compiler.js; }; f",
|
|
164
|
+
"migrate:up": "migrate up --store ./migrations-utils/migrate.js --migrations-dir ./migrations --compiler ts:./node_modules/@lenne.tech/nest-server/dist/core/modules/migrate/helpers/ts-compiler.js",
|
|
165
|
+
"migrate:down": "migrate down --store ./migrations-utils/migrate.js --migrations-dir ./migrations --compiler ts:./node_modules/@lenne.tech/nest-server/dist/core/modules/migrate/helpers/ts-compiler.js",
|
|
166
|
+
"migrate:list": "migrate list --store ./migrations-utils/migrate.js --migrations-dir ./migrations --compiler ts:./node_modules/@lenne.tech/nest-server/dist/core/modules/migrate/helpers/ts-compiler.js"
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
**Environment-specific scripts (optional):**
|
|
172
|
+
```json
|
|
173
|
+
{
|
|
174
|
+
"migrate:develop:up": "NODE_ENV=develop migrate up --store ./migrations-utils/migrate.js --migrations-dir ./migrations --compiler ts:./node_modules/@lenne.tech/nest-server/dist/core/modules/migrate/helpers/ts-compiler.js",
|
|
175
|
+
"migrate:prod:up": "NODE_ENV=production migrate up --store ./migrations-utils/migrate.js --migrations-dir ./migrations --compiler ts:./node_modules/@lenne.tech/nest-server/dist/core/modules/migrate/helpers/ts-compiler.js"
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### Step 7: Verify
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
npm install
|
|
183
|
+
npm run migrate:list # Should show existing migrations
|
|
184
|
+
npm run migrate:create test # Should create new migration
|
|
185
|
+
rm migrations/*-test.ts # Clean up
|
|
186
|
+
npm run build && npm test
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
## Compatibility Notes
|
|
192
|
+
|
|
193
|
+
| What | Status |
|
|
194
|
+
|------|--------|
|
|
195
|
+
| Existing migration files | ✅ Unchanged |
|
|
196
|
+
| Migration state in MongoDB | ✅ Same format, no data loss |
|
|
197
|
+
| Projects without @nodepit | ✅ No action needed |
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
## Troubleshooting
|
|
202
|
+
|
|
203
|
+
| Issue | Solution |
|
|
204
|
+
|-------|----------|
|
|
205
|
+
| `migrate` command not found | Use `npx migrate` or ensure nest-server is installed |
|
|
206
|
+
| `ts-node is required` | `npm install --save-dev ts-node` |
|
|
207
|
+
| `Cannot find module '../src/config.env'` | Use `require('../src/config.env')` and access `config.default.mongoose.uri` |
|
|
208
|
+
| Migrations run on multiple nodes | Add lock collection: `createMigrationStore(uri, 'migrations', 'migration_lock')` |
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
## File Structure After Migration
|
|
213
|
+
|
|
214
|
+
```
|
|
215
|
+
migrations-utils/
|
|
216
|
+
├── migrate.js # Required (7 lines) - uses createMigrationStore
|
|
217
|
+
└── db.ts # Optional (5 lines) - compatibility wrapper for old migrations
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
**Deleted:** `template.ts`, `ts-compiler.js` (now provided by nest-server)
|
|
221
|
+
|
|
222
|
+
---
|
|
223
|
+
|
|
224
|
+
## Module Documentation
|
|
225
|
+
|
|
226
|
+
- **README:** [src/core/modules/migrate/README.md](../src/core/modules/migrate/README.md)
|
|
227
|
+
- **@nodepit Migration:** [src/core/modules/migrate/MIGRATION_FROM_NODEPIT.md](../src/core/modules/migrate/MIGRATION_FROM_NODEPIT.md)
|
|
228
|
+
|
|
229
|
+
---
|
|
230
|
+
|
|
231
|
+
## References
|
|
232
|
+
|
|
233
|
+
- [nest-server-starter](https://github.com/lenneTech/nest-server-starter) (reference implementation)
|
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
# Migration Guide: 11.6.x → 11.7.x
|
|
2
|
+
|
|
3
|
+
## TL;DR
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @lenne.tech/nest-server@11.7.x
|
|
7
|
+
npm run build && npm test # Done! No breaking changes.
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
**New in 11.7.x:** Simplified `CoreModule.forRoot(envConfig)` for IAM-only projects.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Overview
|
|
15
|
+
|
|
16
|
+
| Category | Details |
|
|
17
|
+
|----------|---------|
|
|
18
|
+
| **Breaking Changes** | None |
|
|
19
|
+
| **New Features** | Simplified CoreModule signature, Legacy endpoint control, IAuthProvider interface, Migration status query, Bidirectional password sync |
|
|
20
|
+
| **Bugfixes** | Improved module inheritance pattern for BetterAuth |
|
|
21
|
+
| **Migration Effort** | ~5 minutes (package update only) |
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Choose Your Scenario
|
|
26
|
+
|
|
27
|
+
| Scenario | Use When | CoreModule Signature | Path |
|
|
28
|
+
|----------|----------|---------------------|------|
|
|
29
|
+
| **Legacy Only** | Existing project, no BetterAuth needed | `CoreModule.forRoot(AuthService, AuthModule, envConfig)` | [Path A](#path-a-keep-legacy-auth-no-changes-required) |
|
|
30
|
+
| **Legacy + IAM** | Existing project, migrating to BetterAuth | `CoreModule.forRoot(AuthService, AuthModule, envConfig)` | [Path B](#path-b-add-betterauth-migration-scenario) |
|
|
31
|
+
| **IAM Only** | New project, BetterAuth from start | `CoreModule.forRoot(envConfig)` *(New!)* | [Path C](#path-c-new-project-with-iam-only) |
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## Quick Migration (No Breaking Changes)
|
|
36
|
+
|
|
37
|
+
Since there are no breaking changes, the migration is straightforward:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
# Update package
|
|
41
|
+
npm install @lenne.tech/nest-server@11.7.x
|
|
42
|
+
|
|
43
|
+
# Verify build
|
|
44
|
+
npm run build
|
|
45
|
+
|
|
46
|
+
# Run tests
|
|
47
|
+
npm test
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
**Done!** All existing code continues to work without modifications.
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## What's New in 11.7.x
|
|
55
|
+
|
|
56
|
+
### 1. Simplified CoreModule Signature (IAM-Only)
|
|
57
|
+
|
|
58
|
+
New single-parameter signature for projects that only use BetterAuth:
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
// server.module.ts - NEW: IAM-only (recommended for new projects)
|
|
62
|
+
@Module({
|
|
63
|
+
imports: [
|
|
64
|
+
CoreModule.forRoot(envConfig), // Simple! No AuthService/AuthModule needed
|
|
65
|
+
BetterAuthModule.forRoot({
|
|
66
|
+
config: envConfig.betterAuth,
|
|
67
|
+
fallbackSecrets: [envConfig.jwt?.secret],
|
|
68
|
+
}),
|
|
69
|
+
// ... other modules
|
|
70
|
+
],
|
|
71
|
+
})
|
|
72
|
+
export class ServerModule {}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
**Benefits:**
|
|
76
|
+
- No need to create AuthService or AuthModule for new projects
|
|
77
|
+
- GraphQL subscriptions authenticate via BetterAuth sessions
|
|
78
|
+
- Cleaner setup for modern projects
|
|
79
|
+
|
|
80
|
+
**The 3-parameter signature is now `@deprecated` for new projects** but remains fully functional for existing projects during migration.
|
|
81
|
+
|
|
82
|
+
### 2. Legacy Endpoint Control (`auth.legacyEndpoints`)
|
|
83
|
+
|
|
84
|
+
New configuration option to disable legacy auth endpoints after BetterAuth migration:
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
// config.env.ts
|
|
88
|
+
{
|
|
89
|
+
auth: {
|
|
90
|
+
legacyEndpoints: {
|
|
91
|
+
enabled: true, // Default: true
|
|
92
|
+
graphql: true, // Control GraphQL endpoints separately
|
|
93
|
+
rest: true, // Control REST endpoints separately
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
When disabled, legacy endpoints return HTTP 410 Gone with `LegacyAuthDisabledException`.
|
|
100
|
+
|
|
101
|
+
**Affected Endpoints:**
|
|
102
|
+
- GraphQL: `signIn`, `signUp`, `logout`, `refreshToken`
|
|
103
|
+
- REST: `POST /auth/signin`, `POST /auth/signup`, `GET /auth/logout`, `GET /auth/refresh-token`
|
|
104
|
+
|
|
105
|
+
### 3. Bidirectional Password Synchronization
|
|
106
|
+
|
|
107
|
+
Passwords are now synchronized between Legacy Auth and BetterAuth:
|
|
108
|
+
|
|
109
|
+
| Direction | Flow | Password Storage |
|
|
110
|
+
|-----------|------|------------------|
|
|
111
|
+
| Legacy → IAM | User signs up via Legacy | `bcrypt(sha256(pw))` + `scrypt(sha256(pw))` |
|
|
112
|
+
| IAM → Legacy | User signs up via BetterAuth | `scrypt(sha256(pw))` + `bcrypt(sha256(pw))` |
|
|
113
|
+
|
|
114
|
+
**Requirement:** Inject `BetterAuthUserMapper` in your `UserService`:
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
// user.service.ts
|
|
118
|
+
constructor(
|
|
119
|
+
// ... other params ...
|
|
120
|
+
@Optional() private readonly betterAuthUserMapper?: BetterAuthUserMapper,
|
|
121
|
+
) {
|
|
122
|
+
super(configService, emailService, mainDbModel, mainModelConstructor, { betterAuthUserMapper });
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### 4. IAuthProvider Interface
|
|
127
|
+
|
|
128
|
+
New abstraction layer for authentication providers (preparation for future version):
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
interface IAuthProvider {
|
|
132
|
+
decodeJwt(token: string): JwtPayload;
|
|
133
|
+
validateUser(payload: JwtPayload): Promise<any>;
|
|
134
|
+
signToken(user: any, expiresIn?: string): string;
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### 5. Migration Status Query
|
|
139
|
+
|
|
140
|
+
GraphQL query for monitoring BetterAuth migration progress (admin only):
|
|
141
|
+
|
|
142
|
+
```graphql
|
|
143
|
+
query {
|
|
144
|
+
betterAuthMigrationStatus {
|
|
145
|
+
totalUsers
|
|
146
|
+
fullyMigratedUsers
|
|
147
|
+
pendingMigrationUsers
|
|
148
|
+
migrationPercentage
|
|
149
|
+
canDisableLegacyAuth
|
|
150
|
+
pendingUserEmails
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### 6. Deprecation Warnings
|
|
156
|
+
|
|
157
|
+
JSDoc `@deprecated` comments added to legacy auth endpoints and the 3-parameter CoreModule signature.
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## Detailed Migration Paths
|
|
162
|
+
|
|
163
|
+
### Path A: Keep Legacy Auth (No Changes Required)
|
|
164
|
+
|
|
165
|
+
If you're not using BetterAuth:
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
npm install @lenne.tech/nest-server@11.7.x
|
|
169
|
+
npm run build && npm test
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Your existing code continues to work unchanged.
|
|
173
|
+
|
|
174
|
+
### Path B: Add BetterAuth (Migration Scenario)
|
|
175
|
+
|
|
176
|
+
For existing projects adding BetterAuth alongside Legacy Auth:
|
|
177
|
+
|
|
178
|
+
1. **Update Package**
|
|
179
|
+
```bash
|
|
180
|
+
npm install @lenne.tech/nest-server@11.7.x
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
2. **Keep Existing CoreModule Signature**
|
|
184
|
+
```typescript
|
|
185
|
+
// server.module.ts - Keep your existing setup
|
|
186
|
+
CoreModule.forRoot(AuthService, AuthModule.forRoot(envConfig.jwt), envConfig)
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
3. **Add BetterAuth Module**
|
|
190
|
+
Follow the [BetterAuth Integration Checklist](../src/core/modules/better-auth/INTEGRATION-CHECKLIST.md)
|
|
191
|
+
|
|
192
|
+
4. **Configure Legacy Endpoints**
|
|
193
|
+
```typescript
|
|
194
|
+
// config.env.ts
|
|
195
|
+
auth: {
|
|
196
|
+
legacyEndpoints: { enabled: true } // Keep during migration
|
|
197
|
+
}
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
5. **Monitor Migration Progress**
|
|
201
|
+
```graphql
|
|
202
|
+
query { betterAuthMigrationStatus { migrationPercentage, canDisableLegacyAuth } }
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
6. **Disable Legacy When Ready**
|
|
206
|
+
```typescript
|
|
207
|
+
auth: {
|
|
208
|
+
legacyEndpoints: { enabled: false } // After all users migrated
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### Path C: New Project with IAM Only
|
|
213
|
+
|
|
214
|
+
For new projects starting fresh with BetterAuth:
|
|
215
|
+
|
|
216
|
+
1. **Install Package**
|
|
217
|
+
```bash
|
|
218
|
+
npm install @lenne.tech/nest-server@11.7.x
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
2. **Configure ServerModule**
|
|
222
|
+
```typescript
|
|
223
|
+
// server.module.ts
|
|
224
|
+
@Module({
|
|
225
|
+
imports: [
|
|
226
|
+
CoreModule.forRoot(envConfig), // Simplified! No AuthService/AuthModule needed
|
|
227
|
+
BetterAuthModule.forRoot({
|
|
228
|
+
config: envConfig.betterAuth,
|
|
229
|
+
fallbackSecrets: [envConfig.jwt?.secret],
|
|
230
|
+
}),
|
|
231
|
+
// ... other modules
|
|
232
|
+
],
|
|
233
|
+
})
|
|
234
|
+
export class ServerModule {}
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
3. **Configure config.env.ts**
|
|
238
|
+
```typescript
|
|
239
|
+
// config.env.ts
|
|
240
|
+
auth: {
|
|
241
|
+
legacyEndpoints: { enabled: false } // Disable Legacy endpoints
|
|
242
|
+
},
|
|
243
|
+
betterAuth: {
|
|
244
|
+
jwt: {}, // Enable JWT tokens
|
|
245
|
+
twoFactor: {}, // Enable 2FA (optional)
|
|
246
|
+
passkey: {}, // Enable Passkeys (optional)
|
|
247
|
+
}
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
4. **Follow Integration Checklist**
|
|
251
|
+
See [BetterAuth Integration Checklist](../src/core/modules/better-auth/INTEGRATION-CHECKLIST.md) for required files.
|
|
252
|
+
|
|
253
|
+
---
|
|
254
|
+
|
|
255
|
+
## Compatibility Notes
|
|
256
|
+
|
|
257
|
+
### Module Inheritance Pattern
|
|
258
|
+
|
|
259
|
+
Projects extending `CoreAuthResolver` and `CoreAuthController` continue to work seamlessly. Common patterns observed:
|
|
260
|
+
|
|
261
|
+
**Pattern 1: Override with authService call (common) - MUST call check method**
|
|
262
|
+
```typescript
|
|
263
|
+
@Resolver()
|
|
264
|
+
export class AuthResolver extends CoreAuthResolver {
|
|
265
|
+
override async signIn(input: SignInInput, ...): Promise<Auth> {
|
|
266
|
+
this.checkLegacyGraphQLEnabled('signIn'); // Required!
|
|
267
|
+
return this.authService.signIn(input, ...);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
```
|
|
271
|
+
⚠️ **Important:** When overriding `signIn`, `signUp`, `logout`, or `refreshToken`, you MUST call the protected `checkLegacyGraphQLEnabled()` method. Otherwise, the `auth.legacyEndpoints.enabled: false` configuration will be ignored and legacy endpoints remain accessible.
|
|
272
|
+
|
|
273
|
+
**Pattern 2: Simple extension (no overrides)**
|
|
274
|
+
```typescript
|
|
275
|
+
@Resolver()
|
|
276
|
+
export class AuthResolver extends CoreAuthResolver {}
|
|
277
|
+
```
|
|
278
|
+
This pattern benefits from the new deprecation warnings in IDE.
|
|
279
|
+
|
|
280
|
+
### Custom Role Enums
|
|
281
|
+
|
|
282
|
+
Projects using custom role enums (e.g., `CompanyRoles`) instead of `RoleEnum` continue to work without changes.
|
|
283
|
+
|
|
284
|
+
### Additional Auth Methods
|
|
285
|
+
|
|
286
|
+
Custom methods like `loginAsCompany`, `getCurrentUser`, or `sendVerificationMail` are unaffected.
|
|
287
|
+
|
|
288
|
+
---
|
|
289
|
+
|
|
290
|
+
## Client Configuration
|
|
291
|
+
|
|
292
|
+
New clients should hash passwords with SHA256 before sending:
|
|
293
|
+
|
|
294
|
+
```typescript
|
|
295
|
+
// auth-client.ts (Nuxt/Vue example)
|
|
296
|
+
import { createAuthClient } from 'better-auth/vue';
|
|
297
|
+
|
|
298
|
+
const baseClient = createAuthClient({
|
|
299
|
+
baseURL: import.meta.env.VITE_API_URL,
|
|
300
|
+
basePath: '/iam', // Must match server config
|
|
301
|
+
plugins: [/* ... */],
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
// Wrap signIn/signUp to hash passwords
|
|
305
|
+
export const authClient = {
|
|
306
|
+
...baseClient,
|
|
307
|
+
signIn: {
|
|
308
|
+
...baseClient.signIn,
|
|
309
|
+
email: async (params) => {
|
|
310
|
+
const hashedPassword = await sha256(params.password);
|
|
311
|
+
return baseClient.signIn.email({ ...params, password: hashedPassword });
|
|
312
|
+
},
|
|
313
|
+
},
|
|
314
|
+
// ... same for signUp, resetPassword, etc.
|
|
315
|
+
};
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
The server accepts both plain and SHA256-hashed passwords but **new clients should always hash**.
|
|
319
|
+
|
|
320
|
+
---
|
|
321
|
+
|
|
322
|
+
## Troubleshooting
|
|
323
|
+
|
|
324
|
+
### Build Errors
|
|
325
|
+
|
|
326
|
+
If type errors occur related to `auth` configuration:
|
|
327
|
+
|
|
328
|
+
```bash
|
|
329
|
+
rm -rf node_modules package-lock.json
|
|
330
|
+
npm install
|
|
331
|
+
npm run build
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
### Legacy Endpoints Return 410
|
|
335
|
+
|
|
336
|
+
If legacy endpoints unexpectedly return 410 Gone:
|
|
337
|
+
1. Check `config.auth.legacyEndpoints.enabled` is not `false`
|
|
338
|
+
2. Remove the `auth` configuration block to use defaults
|
|
339
|
+
|
|
340
|
+
### Tests Fail
|
|
341
|
+
|
|
342
|
+
1. Ensure MongoDB is running
|
|
343
|
+
2. Run with debug: `npm run test:e2e-doh`
|
|
344
|
+
3. Check configuration matches test environment expectations
|
|
345
|
+
|
|
346
|
+
### GraphQL Subscriptions in IAM-Only Mode
|
|
347
|
+
|
|
348
|
+
GraphQL Subscriptions are fully supported in IAM-only mode. If authentication fails, check:
|
|
349
|
+
1. Client sends `Authorization: Bearer <session-token>` in WebSocket connection params
|
|
350
|
+
2. BetterAuth is configured: `betterAuth: { jwt: {} }` (JWT plugin enables token validation)
|
|
351
|
+
3. Session is valid and not expired
|
|
352
|
+
|
|
353
|
+
---
|
|
354
|
+
|
|
355
|
+
## Version Comparison
|
|
356
|
+
|
|
357
|
+
| Version | Feature | Status |
|
|
358
|
+
|---------|---------|--------|
|
|
359
|
+
| 11.6.x | BetterAuth module | Introduced |
|
|
360
|
+
| 11.7.x | Simplified CoreModule signature | New |
|
|
361
|
+
| 11.7.x | IAM-only GraphQL Subscriptions | New |
|
|
362
|
+
| 11.7.x | Legacy endpoint control | New |
|
|
363
|
+
| 11.7.x | Bidirectional password sync | New |
|
|
364
|
+
| 11.7.x | IAuthProvider interface | New |
|
|
365
|
+
| 11.7.x | Migration status query | New |
|
|
366
|
+
| Future | BetterAuth default | Planned |
|
|
367
|
+
|
|
368
|
+
---
|
|
369
|
+
|
|
370
|
+
## Module Documentation
|
|
371
|
+
|
|
372
|
+
For detailed information about affected modules, see:
|
|
373
|
+
|
|
374
|
+
### Auth Module (Legacy Auth)
|
|
375
|
+
|
|
376
|
+
- **Location:** `src/core/modules/auth/`
|
|
377
|
+
- **Key Files:**
|
|
378
|
+
- `core-auth.resolver.ts` - GraphQL endpoints with deprecation warnings
|
|
379
|
+
- `core-auth.controller.ts` - REST endpoints with deprecation warnings
|
|
380
|
+
- `interfaces/auth-provider.interface.ts` - New IAuthProvider interface
|
|
381
|
+
|
|
382
|
+
### BetterAuth Module (IAM)
|
|
383
|
+
|
|
384
|
+
- **README:** [src/core/modules/better-auth/README.md](../src/core/modules/better-auth/README.md)
|
|
385
|
+
- **Integration Checklist:** [src/core/modules/better-auth/INTEGRATION-CHECKLIST.md](../src/core/modules/better-auth/INTEGRATION-CHECKLIST.md)
|
|
386
|
+
- **Reference Implementation:** `src/server/modules/better-auth/`
|
|
387
|
+
|
|
388
|
+
---
|
|
389
|
+
|
|
390
|
+
## References
|
|
391
|
+
|
|
392
|
+
- [Module Deprecation Roadmap](../.claude/rules/module-deprecation.md)
|
|
393
|
+
- [nest-server-starter](https://github.com/lenneTech/nest-server-starter) (reference implementation)
|
|
394
|
+
- [BetterAuth README](../src/core/modules/better-auth/README.md)
|