@lenne.tech/nest-server 11.43.8 → 11.43.9

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.
@@ -0,0 +1,43 @@
1
+ # Migration Guide: 11.43.8 → 11.43.9
2
+
3
+ ## Overview
4
+
5
+ | Category | Details |
6
+ |---|---|
7
+ | **Breaking Changes** | None |
8
+ | **New Features** | None |
9
+ | **Bugfixes** | `POST /iam/revoke-session` with `{ sessionId }` ended nothing for a user the legacy migration linked (§1) |
10
+ | **Migration Effort** | None |
11
+
12
+ 11.43.9 is a patch on the 11.x line, published under the dist-tag `latest-11`. The same fix ships in 12.7.2 (`latest`)
13
+ and 12.6.3 (`latest-12.6`).
14
+
15
+ ## Quick Migration
16
+
17
+ ```bash
18
+ pnpm add @lenne.tech/nest-server@11.43.9
19
+ pnpm run update # nest-server-starter based projects
20
+ pnpm run build
21
+ pnpm test
22
+ ```
23
+
24
+ **Vendor mode**: `/lt-dev:backend:update-nest-server-core --target 11.43.9` (without `--target` the updater syncs to the
25
+ latest tag, which is on a newer line).
26
+
27
+ ## 1. `revoke-session` by id for users the legacy migration linked
28
+
29
+ **Why:** since 11.43.8, `POST /iam/revoke-session` accepts `{ sessionId }` and looks the session up among the caller's own
30
+ sessions. It looked the caller up under `user.id`. The session lookup prefers a **stored** `id` field over `_id`. When
31
+ the legacy migration links a user (on its first IAM sign-in, for example a user created through `POST /users` or the
32
+ legacy sign-up), it writes an `id` of its own next to `_id`. Every session references `_id`. So for such a user no
33
+ session was found, nothing was revoked, and the request still answered `{ status: true }`. The error went toward the
34
+ safe side: never another user's session.
35
+
36
+ **What changed:** the caller is looked up under the `userId` of its own session. The ownership check is unchanged.
37
+
38
+ **Your project:** nothing to do. A project that copied `resolveRevokeSessionId()` into its own core takes the session's
39
+ `userId` first (`req.betterAuthSession.session.userId`).
40
+
41
+ ## References
42
+
43
+ - `src/core/modules/better-auth/core-better-auth-api.middleware.ts`: `resolveRevokeSessionId()`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lenne.tech/nest-server",
3
- "version": "11.43.8",
3
+ "version": "11.43.9",
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",
@@ -142,10 +142,18 @@ export class CoreBetterAuthApiMiddleware implements NestMiddleware {
142
142
  return;
143
143
  }
144
144
  const caller = req as unknown as {
145
- betterAuthSession?: { user?: { id?: unknown } };
145
+ betterAuthSession?: { session?: { userId?: unknown }; user?: { id?: unknown } };
146
146
  betterAuthUser?: { id?: unknown };
147
147
  };
148
- const userId = caller.betterAuthSession?.user?.id ?? caller.betterAuthUser?.id;
148
+ // The id the sessions are stored under, from the caller's own session (11.43.9, DEV-4133). `user.id` is not it for
149
+ // every user: the session lookup prefers a STORED `id`, and the legacy migration (`migrateAccountToIam()`) writes
150
+ // one of its own next to `_id`, which is what every session references — so a migrated user's sessions were never
151
+ // found and nothing was revoked. The ownership check stays in sessionTokenOfUser().
152
+ const sessionUserId = caller.betterAuthSession?.session?.userId;
153
+ const userId =
154
+ (typeof sessionUserId === 'string' && sessionUserId ? sessionUserId : undefined) ??
155
+ caller.betterAuthSession?.user?.id ??
156
+ caller.betterAuthUser?.id;
149
157
  const token =
150
158
  typeof userId === 'string' && userId
151
159
  ? await this.betterAuthService.sessionTokenOfUser(userId, sessionId)