@lenne.tech/nest-server 12.11.1 → 12.11.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.
- package/.claude/rules/better-auth.md +1 -0
- package/.claude/rules/testing.md +4 -4
- package/FRAMEWORK-API.md +1 -1
- package/dist/core/common/helpers/http-stream-auth.helper.js +2 -2
- package/dist/core/common/helpers/http-stream-auth.helper.js.map +1 -1
- package/dist/core/modules/better-auth/better-auth-cookie-prefix.helper.d.ts +2 -0
- package/dist/core/modules/better-auth/better-auth-cookie-prefix.helper.js +5 -0
- package/dist/core/modules/better-auth/better-auth-cookie-prefix.helper.js.map +1 -1
- package/dist/core/modules/better-auth/core-better-auth.middleware.js +4 -2
- package/dist/core/modules/better-auth/core-better-auth.middleware.js.map +1 -1
- package/migration-guides/12.11.1-to-12.11.2.md +76 -0
- package/package.json +5 -5
- package/src/core/common/helpers/http-stream-auth.helper.ts +6 -6
- package/src/core/modules/better-auth/better-auth-cookie-prefix.helper.ts +17 -0
- package/src/core/modules/better-auth/core-better-auth.middleware.ts +9 -4
- package/src/core/modules/sync/README.md +1 -1
|
@@ -687,6 +687,7 @@ handed Better-Auth the user's NEWEST session for a JWT request.
|
|
|
687
687
|
| A session deleted outside Better-Auth's adapter is caught by the cache interval only (`jwtSessionCacheTtlMs`, 10 s) | the immediate forget runs from Better-Auth's `session.delete` hook (`wsSessionRevocationPlugin()`); delete through Better-Auth |
|
|
688
688
|
| The cache lives in the import-free leaf `core-better-auth-jwt-session.cache.ts`, bounded, keyed by session id and checked against the user | config, service and user mapper reach it without importing each other; an entry never vouches for another user |
|
|
689
689
|
| After a session rotation the answer's `token` is the JWT of the NEW session — also when Better-Auth's answer names no token (two-factor disable, 12.11.1) | the old JWT names a deleted session and answers 401 |
|
|
690
|
+
| The JWT cookie is read under `resolveJwtCookieName()`: `<COOKIE_PREFIX>-jwt-token`, else `lt-jwt-token`, no fallback while a prefix is set (12.11.2) | `@lenne.tech/nuxt-extensions` names it after `NUXT_PUBLIC_COOKIE_PREFIX`; a fixed `lt-jwt-token` left every cookie-only request (SSR, passkey, stream re-check) anonymous with a prefix. Mutations `jwt-cookie-name-ignores-cookie-prefix`, `middleware-jwt-cookie-ignores-prefix`, `stream-recheck-jwt-cookie-ignores-prefix` |
|
|
690
691
|
|
|
691
692
|
Pinned by `tests/unit/better-auth-jwt-session-binding.spec.ts` and `tests/better-auth-jwt-session.e2e-spec.ts`.
|
|
692
693
|
|
package/.claude/rules/testing.md
CHANGED
|
@@ -412,7 +412,7 @@ pnpm run check:mutations -- --id=<id> # one mutation
|
|
|
412
412
|
pnpm run check:mutations -- --list # the registry, without running anything
|
|
413
413
|
pnpm run check:mutations -- --allow-dirty # when the fix and its evidence share a working tree
|
|
414
414
|
pnpm run check:mutations -- --jobs=4 # N mutations at a time (default: 2, or 4 on >=12 cores)
|
|
415
|
-
pnpm run check:mutations -- --no-infra # only the
|
|
415
|
+
pnpm run check:mutations -- --no-infra # only the 518 that need no MongoDB
|
|
416
416
|
pnpm run check:mutations -- --since=<ref> # only mutations touching files changed since <ref>
|
|
417
417
|
pnpm run check:mutations -- --shard=2/4 # this job's quarter of the selection (CI splits the full run)
|
|
418
418
|
```
|
|
@@ -432,7 +432,7 @@ when the registry, a vitest config or a setup file changed, since those can move
|
|
|
432
432
|
commit, and in CI alongside the publish without blocking it. The price of caching is a cache that
|
|
433
433
|
has to model each spec's full dependency closure correctly, and getting that wrong produces a stale
|
|
434
434
|
PASS for a test that has since gone vacuous — exactly what the gate is there to prevent. Bad trade
|
|
435
|
-
at
|
|
435
|
+
at 768 mutations.
|
|
436
436
|
|
|
437
437
|
**Decided 2026-10-03 (repo owner): keep the full run.** Measured at 128 mutations, the CI job for
|
|
438
438
|
11.41.6 took **14 minutes**. The trigger to revisit is that wall time, not the mutation count —
|
|
@@ -503,9 +503,9 @@ exactly the environment where the answer matters.
|
|
|
503
503
|
|
|
504
504
|
### The cost is vitest's cold start, not the tests
|
|
505
505
|
|
|
506
|
-
Worth knowing before optimising the wrong thing: the specs behind all
|
|
506
|
+
Worth knowing before optimising the wrong thing: the specs behind all 250 e2e mutations add up to
|
|
507
507
|
**~40 seconds**. The step takes ~740s. The remaining ~700s is paying vitest's startup — process
|
|
508
|
-
spawn, transform, module graph, mongod connect, DB create and drop — once per mutation,
|
|
508
|
+
spawn, transform, module graph, mongod connect, DB create and drop — once per mutation, 768 times.
|
|
509
509
|
That work is largely single-threaded I/O and barely scales with cores: the full registry measures
|
|
510
510
|
**744s on a 12-core laptop and 777s on a 4-vCPU CI runner**.
|
|
511
511
|
|
package/FRAMEWORK-API.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @lenne.tech/nest-server — Framework API Reference
|
|
2
2
|
|
|
3
|
-
> Auto-generated from source code as of 2026-11-24 (v12.11.
|
|
3
|
+
> Auto-generated from source code as of 2026-11-24 (v12.11.2)
|
|
4
4
|
> File: `FRAMEWORK-API.md` — compact, machine-readable API surface for Claude Code
|
|
5
5
|
|
|
6
6
|
## CoreModule.forRoot()
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { hasApiTokenCredential } from '../../modules/api-token/core-api-token.helpers.js';
|
|
2
|
+
import { resolveJwtCookieName } from '../../modules/better-auth/better-auth-cookie-prefix.helper.js';
|
|
2
3
|
import { isLegacyJwt } from '../../modules/better-auth/core-better-auth-token.helper.js';
|
|
3
4
|
import { extractSessionToken, parseCookieHeader } from '../../modules/better-auth/core-better-auth-web.helper.js';
|
|
4
5
|
import { getBetterAuthTokenService } from '../../modules/better-auth/core-better-auth.registry.js';
|
|
5
6
|
import { ConfigService } from '../services/config.service.js';
|
|
6
7
|
import { getWsConnection, noteWsConnectionTenant, readWsTenantHeader, recheckHttpStreamInPlace, registerWsConnection, } from './graphql-ws-connection.helper.js';
|
|
7
|
-
const JWT_COOKIE_NAME = 'lt-jwt-token';
|
|
8
8
|
function firstHeaderValue(value) {
|
|
9
9
|
const first = Array.isArray(value) ? value[0] : value;
|
|
10
10
|
return typeof first === 'string' && first ? first : undefined;
|
|
@@ -30,7 +30,7 @@ function credentialTokens(credential) {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
else {
|
|
33
|
-
const jwt = cookies?.[
|
|
33
|
+
const jwt = cookies?.[resolveJwtCookieName()];
|
|
34
34
|
if (typeof jwt === 'string' && jwt.split('.').length === 3 && !isLegacy(jwt)) {
|
|
35
35
|
add(jwt);
|
|
36
36
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-stream-auth.helper.js","sourceRoot":"","sources":["../../../../src/core/common/helpers/http-stream-auth.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mDAAmD,CAAC;AAC1F,OAAO,EAAE,WAAW,EAAE,MAAM,4DAA4D,CAAC;AACzF,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,0DAA0D,CAAC;AAClH,OAAO,EAAE,yBAAyB,EAAE,MAAM,wDAAwD,CAAC;AACnG,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EACL,eAAe,EAEf,sBAAsB,EACtB,kBAAkB,EAClB,wBAAwB,EACxB,oBAAoB,GAErB,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"http-stream-auth.helper.js","sourceRoot":"","sources":["../../../../src/core/common/helpers/http-stream-auth.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mDAAmD,CAAC;AAC1F,OAAO,EAAE,oBAAoB,EAAE,MAAM,+DAA+D,CAAC;AACrG,OAAO,EAAE,WAAW,EAAE,MAAM,4DAA4D,CAAC;AACzF,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,0DAA0D,CAAC;AAClH,OAAO,EAAE,yBAAyB,EAAE,MAAM,wDAAwD,CAAC;AACnG,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC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M,EAAE,CAAC;QACX,sBAAsB,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAC7C,CAAC;IACD,MAAM,cAAc,GAClB,YAAY,CAAC,cAAc,KAAK,KAAK;QACnC,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,CAAC,YAAY,CAAC,cAAc,IAAI,+BAA+B,CAAC,OAAO,CAAC,CAAC,CAAC;IAChF,IAAI,cAAc,EAAE,CAAC;QACnB,MAAM,wBAAwB,CAAC,UAAU,EAAE,EAAE,cAAc,EAAE,YAAY,EAAE,kBAAkB,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC5G,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export declare function resolveBetterAuthCookiePrefix(basePath: string, env?: NodeJS.ProcessEnv): string;
|
|
2
2
|
export declare function resolveBetterAuthSessionCookieName(basePath: string, env?: NodeJS.ProcessEnv): string;
|
|
3
|
+
export declare const DEFAULT_JWT_COOKIE_NAME = "lt-jwt-token";
|
|
4
|
+
export declare function resolveJwtCookieName(env?: NodeJS.ProcessEnv): string;
|
|
3
5
|
export declare function detectCookiePrefixDrift(resolvedPrefix: string, programmaticOptionsAdvanced: unknown): null | string;
|
|
@@ -9,6 +9,11 @@ export function resolveBetterAuthCookiePrefix(basePath, env = process.env) {
|
|
|
9
9
|
export function resolveBetterAuthSessionCookieName(basePath, env = process.env) {
|
|
10
10
|
return `${resolveBetterAuthCookiePrefix(basePath, env)}.session_token`;
|
|
11
11
|
}
|
|
12
|
+
export const DEFAULT_JWT_COOKIE_NAME = 'lt-jwt-token';
|
|
13
|
+
export function resolveJwtCookieName(env = process.env) {
|
|
14
|
+
const explicit = sanitizeCookiePrefix(typeof env.COOKIE_PREFIX === 'string' ? env.COOKIE_PREFIX : '');
|
|
15
|
+
return explicit ? `${explicit}-jwt-token` : DEFAULT_JWT_COOKIE_NAME;
|
|
16
|
+
}
|
|
12
17
|
export function detectCookiePrefixDrift(resolvedPrefix, programmaticOptionsAdvanced) {
|
|
13
18
|
if (!programmaticOptionsAdvanced || typeof programmaticOptionsAdvanced !== 'object')
|
|
14
19
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"better-auth-cookie-prefix.helper.js","sourceRoot":"","sources":["../../../../src/core/modules/better-auth/better-auth-cookie-prefix.helper.ts"],"names":[],"mappings":"AAqBA,SAAS,oBAAoB,CAAC,GAAW;IACvC,OAAO,GAAG,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC,CAAC;AACpD,CAAC;AAsBD,MAAM,UAAU,6BAA6B,CAAC,QAAgB,EAAE,MAAyB,OAAO,CAAC,GAAG;IAClG,MAAM,cAAc,GAAG,CAAC,QAAQ,IAAI,MAAM,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACnF,MAAM,QAAQ,GAAG,oBAAoB,CAAC,OAAO,GAAG,CAAC,aAAa,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IACtG,OAAO,QAAQ,IAAI,cAAc,CAAC;AACpC,CAAC;AAOD,MAAM,UAAU,kCAAkC,CAAC,QAAgB,EAAE,MAAyB,OAAO,CAAC,GAAG;IACvG,OAAO,GAAG,6BAA6B,CAAC,QAAQ,EAAE,GAAG,CAAC,gBAAgB,CAAC;AACzE,CAAC;AAgBD,MAAM,UAAU,uBAAuB,CAAC,cAAsB,EAAE,2BAAoC;IAClG,IAAI,CAAC,2BAA2B,IAAI,OAAO,2BAA2B,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IACjG,MAAM,kBAAkB,GAAI,2BAAuD,CAAC,YAAY,CAAC;IACjG,IAAI,OAAO,kBAAkB,KAAK,QAAQ,IAAI,kBAAkB,KAAK,cAAc;QAAE,OAAO,IAAI,CAAC;IACjG,OAAO,CACL,kCAAkC,kBAAkB,kCAAkC;QACtF,4BAA4B,cAAc,iDAAiD;QAC3F,2EAA2E,CAC5E,CAAC;AACJ,CAAC"}
|
|
1
|
+
{"version":3,"file":"better-auth-cookie-prefix.helper.js","sourceRoot":"","sources":["../../../../src/core/modules/better-auth/better-auth-cookie-prefix.helper.ts"],"names":[],"mappings":"AAqBA,SAAS,oBAAoB,CAAC,GAAW;IACvC,OAAO,GAAG,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC,CAAC;AACpD,CAAC;AAsBD,MAAM,UAAU,6BAA6B,CAAC,QAAgB,EAAE,MAAyB,OAAO,CAAC,GAAG;IAClG,MAAM,cAAc,GAAG,CAAC,QAAQ,IAAI,MAAM,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACnF,MAAM,QAAQ,GAAG,oBAAoB,CAAC,OAAO,GAAG,CAAC,aAAa,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IACtG,OAAO,QAAQ,IAAI,cAAc,CAAC;AACpC,CAAC;AAOD,MAAM,UAAU,kCAAkC,CAAC,QAAgB,EAAE,MAAyB,OAAO,CAAC,GAAG;IACvG,OAAO,GAAG,6BAA6B,CAAC,QAAQ,EAAE,GAAG,CAAC,gBAAgB,CAAC;AACzE,CAAC;AAGD,MAAM,CAAC,MAAM,uBAAuB,GAAG,cAAc,CAAC;AAWtD,MAAM,UAAU,oBAAoB,CAAC,MAAyB,OAAO,CAAC,GAAG;IACvE,MAAM,QAAQ,GAAG,oBAAoB,CAAC,OAAO,GAAG,CAAC,aAAa,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IACtG,OAAO,QAAQ,CAAC,CAAC,CAAC,GAAG,QAAQ,YAAY,CAAC,CAAC,CAAC,uBAAuB,CAAC;AACtE,CAAC;AAgBD,MAAM,UAAU,uBAAuB,CAAC,cAAsB,EAAE,2BAAoC;IAClG,IAAI,CAAC,2BAA2B,IAAI,OAAO,2BAA2B,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IACjG,MAAM,kBAAkB,GAAI,2BAAuD,CAAC,YAAY,CAAC;IACjG,IAAI,OAAO,kBAAkB,KAAK,QAAQ,IAAI,kBAAkB,KAAK,cAAc;QAAE,OAAO,IAAI,CAAC;IACjG,OAAO,CACL,kCAAkC,kBAAkB,kCAAkC;QACtF,4BAA4B,cAAc,iDAAiD;QAC3F,2EAA2E,CAC5E,CAAC;AACJ,CAAC"}
|
|
@@ -10,6 +10,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
var CoreBetterAuthMiddleware_1;
|
|
11
11
|
import { Injectable, Logger } from '@nestjs/common';
|
|
12
12
|
import { hasApiTokenCredential } from '../api-token/core-api-token.helpers.js';
|
|
13
|
+
import { resolveJwtCookieName } from './better-auth-cookie-prefix.helper.js';
|
|
13
14
|
import { isLegacyJwt } from './core-better-auth-token.helper.js';
|
|
14
15
|
import { CoreBetterAuthUserMapper } from './core-better-auth-user.mapper.js';
|
|
15
16
|
import { convertExpressHeaders, extractSessionToken } from './core-better-auth-web.helper.js';
|
|
@@ -86,9 +87,10 @@ let CoreBetterAuthMiddleware = CoreBetterAuthMiddleware_1 = class CoreBetterAuth
|
|
|
86
87
|
}
|
|
87
88
|
if (!req.user && !req.headers.authorization && this.betterAuthService.isJwtEnabled()) {
|
|
88
89
|
try {
|
|
89
|
-
|
|
90
|
+
const jwtCookieName = resolveJwtCookieName();
|
|
91
|
+
let jwtFromCookie = req.cookies?.[jwtCookieName];
|
|
90
92
|
if (!jwtFromCookie && req.headers.cookie) {
|
|
91
|
-
const match = req.headers.cookie.match(
|
|
93
|
+
const match = req.headers.cookie.match(new RegExp(`(?:^|;\\s*)${jwtCookieName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}=([^;]+)`));
|
|
92
94
|
if (match) {
|
|
93
95
|
jwtFromCookie = decodeURIComponent(match[1]);
|
|
94
96
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-better-auth.middleware.js","sourceRoot":"","sources":["../../../../src/core/modules/better-auth/core-better-auth.middleware.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAkB,MAAM,gBAAgB,CAAC;AAGpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AAC/E,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AACjE,OAAO,EAAyB,wBAAwB,EAAc,MAAM,mCAAmC,CAAC;AAChH,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAC9F,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AA+B/D,IAAM,wBAAwB,gCAA9B,MAAM,wBAAwB;IAIhB;IACA;IAJF,MAAM,GAAG,IAAI,MAAM,CAAC,0BAAwB,CAAC,IAAI,CAAC,CAAC;IAEpE,YACmB,iBAAwC,EACxC,UAAoC;QADpC,sBAAiB,GAAjB,iBAAiB,CAAuB;QACxC,eAAU,GAAV,UAAU,CAA0B;IACpD,CAAC;IAEJ,KAAK,CAAC,GAAG,CAAC,GAA0B,EAAE,IAAc,EAAE,IAAkB;QAEtE,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,SAAS,EAAE,EAAE,CAAC;YACxC,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC;QAGD,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC;YACb,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC;QAKD,IAAI,qBAAqB,CAAC,GAAG,CAAC,EAAE,CAAC;YAC/B,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC;QAKD,IA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IAAI,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,aAAa,IAAI,IAAI,CAAC,iBAAiB,CAAC,YAAY,EAAE,EAAE,CAAC;YACrF,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"core-better-auth.middleware.js","sourceRoot":"","sources":["../../../../src/core/modules/better-auth/core-better-auth.middleware.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAkB,MAAM,gBAAgB,CAAC;AAGpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AAC/E,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAC7E,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AACjE,OAAO,EAAyB,wBAAwB,EAAc,MAAM,mCAAmC,CAAC;AAChH,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAC9F,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AA+B/D,IAAM,wBAAwB,gCAA9B,MAAM,wBAAwB;IAIhB;IACA;IAJF,MAAM,GAAG,IAAI,MAAM,CAAC,0BAAwB,CAAC,IAAI,CAAC,CAAC;IAEpE,YACmB,iBAAwC,EACxC,UAAoC;QADpC,sBAAiB,GAAjB,iBAAiB,CAAuB;QACxC,eAAU,GAAV,UAAU,CAA0B;IACpD,CAAC;IAEJ,KAAK,CAAC,GAAG,CAAC,GAA0B,EAAE,IAAc,EAAE,IAAkB;QAEtE,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,SAAS,EAAE,EAAE,CAAC;YACxC,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC;QAGD,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC;YACb,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC;QAKD,IAAI,qBAAqB,CAAC,GAAG,CAAC,EAAE,CAAC;YAC/B,OAAO,IAA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AC;YAEnD,IAAI,QAAQ,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,MAAM,IAAI,QAAQ,EAAE,CAAC;gBACnE,OAAO,QAAyD,CAAC;YACnE,CAAC;YAED,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,qBAAqB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,EAAE,CAAC,CAAC;YACnG,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;CACF,CAAA;AAxPY,wBAAwB;IADpC,UAAU,EAAE;qCAK2B,qBAAqB;QAC5B,wBAAwB;GAL5C,wBAAwB,CAwPpC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# Migration Guide: 12.11.1 → 12.11.2
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
| Category | Details |
|
|
6
|
+
|---|---|
|
|
7
|
+
| **Breaking Changes** | None |
|
|
8
|
+
| **New Features** | None. `resolveJwtCookieName()` and `DEFAULT_JWT_COOKIE_NAME` name the JWT cookie |
|
|
9
|
+
| **Bugfixes** | With `COOKIE_PREFIX`, the API reads a JWT-mode frontend's JWT cookie under `<prefix>-jwt-token`, the name `@lenne.tech/nuxt-extensions` writes (§1) |
|
|
10
|
+
| **Security** | None |
|
|
11
|
+
| **Migration Effort** | Package update. Only projects that set `COOKIE_PREFIX` and run in JWT mode (`cookies: false`) notice a difference |
|
|
12
|
+
|
|
13
|
+
## Quick Migration
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm add @lenne.tech/nest-server@12.11.2
|
|
17
|
+
pnpm run update # nest-server-starter based projects
|
|
18
|
+
pnpm run build
|
|
19
|
+
pnpm test
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**Vendor mode**: run `/lt-dev:backend:update-nest-server-core` as usual.
|
|
23
|
+
|
|
24
|
+
## 1. Bugfix: the JWT cookie follows `COOKIE_PREFIX`
|
|
25
|
+
|
|
26
|
+
**No action needed.** Keep `COOKIE_PREFIX` (API) and `NUXT_PUBLIC_COOKIE_PREFIX` (app) equal, as before.
|
|
27
|
+
|
|
28
|
+
In JWT mode the frontend keeps the Better-Auth JWT in a cookie as well as sending it as a bearer token. A request that
|
|
29
|
+
carries the cookie but no `Authorization` header is authenticated by `CoreBetterAuthMiddleware` from that cookie: a
|
|
30
|
+
server-side rendered page that forwards the browser's cookies, a passkey request from the app, and the in-place re-check
|
|
31
|
+
of an SSE stream (`registerHttpStream()`).
|
|
32
|
+
|
|
33
|
+
`@lenne.tech/nuxt-extensions` names that cookie `<NUXT_PUBLIC_COOKIE_PREFIX>-jwt-token` when a prefix is set. Up to
|
|
34
|
+
12.11.1 the API read `lt-jwt-token` only. With a prefix such a request was anonymous, and Better-Auth's plugin routes
|
|
35
|
+
(passkey registration, two-factor) answered `401`.
|
|
36
|
+
|
|
37
|
+
| `COOKIE_PREFIX` | JWT cookie read since 12.11.2 | Before |
|
|
38
|
+
|---|---|---|
|
|
39
|
+
| not set | `lt-jwt-token` | `lt-jwt-token` |
|
|
40
|
+
| `acme` | `acme-jwt-token` | `lt-jwt-token` |
|
|
41
|
+
|
|
42
|
+
The prefix is sanitised by the same rule as on the frontend (`[A-Za-z0-9._-]`). The base path does not enter the name,
|
|
43
|
+
unlike the session cookie (`<prefix>.session_token`, else `iam.session_token`). There is no fallback to `lt-jwt-token`
|
|
44
|
+
while `COOKIE_PREFIX` is set: the prefix keeps the apps on one host apart, and the session cookie does not fall back
|
|
45
|
+
either.
|
|
46
|
+
|
|
47
|
+
## 2. Dependencies
|
|
48
|
+
|
|
49
|
+
| Package | 12.11.1 | 12.11.2 |
|
|
50
|
+
|---|---|---|
|
|
51
|
+
| `ai` (optional peer) | 7.0.179 | 7.0.181 |
|
|
52
|
+
| `@aws-sdk/client-s3`, `@aws-sdk/lib-storage`, `@aws-sdk/s3-request-presigner` (optional peers) | 3.1175.0 | 3.1176.0 |
|
|
53
|
+
|
|
54
|
+
Maintenance releases without advisories; the peer ranges are unchanged. The dated `minimumReleaseAgeExclude` entry for
|
|
55
|
+
`mongoose@9.13.0` from 12.11.1 is removed; mongoose 9.13.0 has cleared the release-age gate.
|
|
56
|
+
|
|
57
|
+
## Compatibility Notes
|
|
58
|
+
|
|
59
|
+
| Pattern | Status |
|
|
60
|
+
|---|---|
|
|
61
|
+
| No `COOKIE_PREFIX` | Unchanged |
|
|
62
|
+
| `COOKIE_PREFIX` with cookies (the default `cookies: true`) | Unchanged; the session cookie already followed the prefix |
|
|
63
|
+
| `COOKIE_PREFIX` with `cookies: false` and a matching `NUXT_PUBLIC_COOKIE_PREFIX` | Fixed: the JWT cookie is read |
|
|
64
|
+
| A frontend that sets `COOKIE_PREFIX` on the API but writes `lt-jwt-token` | No longer authenticated through the cookie. Set the same prefix on both sides |
|
|
65
|
+
|
|
66
|
+
## Troubleshooting
|
|
67
|
+
|
|
68
|
+
| Symptom | Cause | Fix |
|
|
69
|
+
|---|---|---|
|
|
70
|
+
| Passkey or 2FA routes answer `401` in JWT mode with a cookie prefix | 12.11.1 or older read only `lt-jwt-token` | Update to 12.11.2 |
|
|
71
|
+
| Still `401` after the update | The API and the app use different prefixes | Set `COOKIE_PREFIX` and `NUXT_PUBLIC_COOKIE_PREFIX` to the same value |
|
|
72
|
+
|
|
73
|
+
## Module Documentation
|
|
74
|
+
|
|
75
|
+
- `src/core/modules/better-auth/better-auth-cookie-prefix.helper.ts`: `resolveJwtCookieName()`, `resolveBetterAuthCookiePrefix()`
|
|
76
|
+
- `migration-guides/11.26.1-to-11.26.2.md`, §1: `COOKIE_PREFIX` and the frontend pairing
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lenne.tech/nest-server",
|
|
3
|
-
"version": "12.11.
|
|
3
|
+
"version": "12.11.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Server framework in TypeScript on top of NestJS: GraphQL and REST APIs on MongoDB, PostgreSQL, MySQL or MariaDB, with authentication, field-level permissions, multi-tenancy, offline sync and an AI assistant.",
|
|
6
6
|
"keywords": [
|
|
@@ -244,9 +244,9 @@
|
|
|
244
244
|
}
|
|
245
245
|
},
|
|
246
246
|
"devDependencies": {
|
|
247
|
-
"@aws-sdk/client-s3": "3.
|
|
248
|
-
"@aws-sdk/lib-storage": "3.
|
|
249
|
-
"@aws-sdk/s3-request-presigner": "3.
|
|
247
|
+
"@aws-sdk/client-s3": "3.1176.0",
|
|
248
|
+
"@aws-sdk/lib-storage": "3.1176.0",
|
|
249
|
+
"@aws-sdk/s3-request-presigner": "3.1176.0",
|
|
250
250
|
"@better-auth/core": "1.7.23",
|
|
251
251
|
"@better-auth/passkey": "1.7.23",
|
|
252
252
|
"@compodoc/compodoc": "2.0.0",
|
|
@@ -274,7 +274,7 @@
|
|
|
274
274
|
"@types/passport": "1.0.17",
|
|
275
275
|
"@types/pg": "8.23.1",
|
|
276
276
|
"@vitest/coverage-v8": "5.1.1",
|
|
277
|
-
"ai": "7.0.
|
|
277
|
+
"ai": "7.0.181",
|
|
278
278
|
"better-auth": "1.7.23",
|
|
279
279
|
"bullmq": "6.7.8",
|
|
280
280
|
"cross-env": "10.1.0",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { hasApiTokenCredential } from '../../modules/api-token/core-api-token.helpers.js';
|
|
2
|
+
import { resolveJwtCookieName } from '../../modules/better-auth/better-auth-cookie-prefix.helper.js';
|
|
2
3
|
import { isLegacyJwt } from '../../modules/better-auth/core-better-auth-token.helper.js';
|
|
3
4
|
import { extractSessionToken, parseCookieHeader } from '../../modules/better-auth/core-better-auth-web.helper.js';
|
|
4
5
|
import { getBetterAuthTokenService } from '../../modules/better-auth/core-better-auth.registry.js';
|
|
@@ -25,15 +26,13 @@ import type { ResolvedTenantContext } from '../services/core-tenant-context.regi
|
|
|
25
26
|
* re-checked in place like a GraphQL WebSocket (`recheckHttpStreamInPlace()`).
|
|
26
27
|
*
|
|
27
28
|
* WHICH CREDENTIALS: the ones `CoreBetterAuthMiddleware` resolves, in its order — the bearer token of the
|
|
28
|
-
* `Authorization` header (a Better-Auth JWT or session token), the
|
|
29
|
+
* `Authorization` header (a Better-Auth JWT or session token), the JWT cookie when no header was sent (`lt-jwt-token`, or
|
|
30
|
+
* `<COOKIE_PREFIX>-jwt-token` with a prefix), then
|
|
29
31
|
* the Better-Auth session cookie (`<prefix>.session_token`, signed or not) — each verified and loaded through
|
|
30
32
|
* Better-Auth's token service, the one the IAM role guard uses. A legacy JWT is Passport's and an API token has checks
|
|
31
33
|
* of its own: neither can be re-run here, and such a stream keeps ending on every re-check.
|
|
32
34
|
*/
|
|
33
35
|
|
|
34
|
-
/** The cookie a JWT-mode frontend keeps the Better-Auth JWT in — the one `CoreBetterAuthMiddleware` reads. */
|
|
35
|
-
const JWT_COOKIE_NAME = 'lt-jwt-token';
|
|
36
|
-
|
|
37
36
|
/** What a request carried to authenticate, as it was when the stream was opened. */
|
|
38
37
|
interface HttpStreamCredential {
|
|
39
38
|
authorization?: string;
|
|
@@ -73,7 +72,8 @@ function credentialTokens(credential: HttpStreamCredential): string[] {
|
|
|
73
72
|
add(token);
|
|
74
73
|
}
|
|
75
74
|
} else {
|
|
76
|
-
|
|
75
|
+
// The cookie `CoreBetterAuthMiddleware` reads: `<COOKIE_PREFIX>-jwt-token`, else `lt-jwt-token` (12.11.2)
|
|
76
|
+
const jwt = cookies?.[resolveJwtCookieName()];
|
|
77
77
|
if (typeof jwt === 'string' && jwt.split('.').length === 3 && !isLegacy(jwt)) {
|
|
78
78
|
add(jwt);
|
|
79
79
|
}
|
|
@@ -90,7 +90,7 @@ function credentialTokens(credential: HttpStreamCredential): string[] {
|
|
|
90
90
|
|
|
91
91
|
/**
|
|
92
92
|
* Build the re-authentication of an HTTP stream from the request that opened it: a function that re-runs the
|
|
93
|
-
* request's Better-Auth credential (bearer token,
|
|
93
|
+
* request's Better-Auth credential (bearer token, JWT cookie, session cookie — see the file comment) and
|
|
94
94
|
* resolves to the user it authenticates as NOW, or to `null` when it no longer does (a signed-out or expired session,
|
|
95
95
|
* an expired JWT).
|
|
96
96
|
*
|
|
@@ -58,6 +58,23 @@ export function resolveBetterAuthSessionCookieName(basePath: string, env: NodeJS
|
|
|
58
58
|
return `${resolveBetterAuthCookiePrefix(basePath, env)}.session_token`;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
+
/** The name of the JWT cookie without `COOKIE_PREFIX`, the one `@lenne.tech/nuxt-extensions` writes by default. */
|
|
62
|
+
export const DEFAULT_JWT_COOKIE_NAME = 'lt-jwt-token';
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The cookie a JWT-mode frontend keeps the Better-Auth JWT in (12.11.2): `<COOKIE_PREFIX>-jwt-token` when `COOKIE_PREFIX`
|
|
66
|
+
* is set, otherwise `lt-jwt-token`. `@lenne.tech/nuxt-extensions` names it the same way from `NUXT_PUBLIC_COOKIE_PREFIX`,
|
|
67
|
+
* sanitised by the same rule. Unlike the session cookie, the basePath never enters the name.
|
|
68
|
+
*
|
|
69
|
+
* There is no fallback to `lt-jwt-token` while `COOKIE_PREFIX` is set: the prefix isolates the apps on one host, and
|
|
70
|
+
* the session cookie does not fall back either. Before 12.11.2 the API read `lt-jwt-token` only, so with a prefix
|
|
71
|
+
* every request without an `Authorization` header (SSR with forwarded cookies, a stream re-check) was anonymous.
|
|
72
|
+
*/
|
|
73
|
+
export function resolveJwtCookieName(env: NodeJS.ProcessEnv = process.env): string {
|
|
74
|
+
const explicit = sanitizeCookiePrefix(typeof env.COOKIE_PREFIX === 'string' ? env.COOKIE_PREFIX : '');
|
|
75
|
+
return explicit ? `${explicit}-jwt-token` : DEFAULT_JWT_COOKIE_NAME;
|
|
76
|
+
}
|
|
77
|
+
|
|
61
78
|
/**
|
|
62
79
|
* Detect a Better-Auth cookie-prefix drift between the value the NestJS layer
|
|
63
80
|
* resolves (via {@link resolveBetterAuthCookiePrefix}) and a programmatic
|
|
@@ -2,6 +2,7 @@ import { Injectable, Logger, NestMiddleware } from '@nestjs/common';
|
|
|
2
2
|
import { NextFunction, Request, Response } from 'express';
|
|
3
3
|
|
|
4
4
|
import { hasApiTokenCredential } from '../api-token/core-api-token.helpers.js';
|
|
5
|
+
import { resolveJwtCookieName } from './better-auth-cookie-prefix.helper.js';
|
|
5
6
|
import { isLegacyJwt } from './core-better-auth-token.helper.js';
|
|
6
7
|
import { BetterAuthSessionUser, CoreBetterAuthUserMapper, MappedUser } from './core-better-auth-user.mapper.js';
|
|
7
8
|
import { convertExpressHeaders, extractSessionToken } from './core-better-auth-web.helper.js';
|
|
@@ -143,14 +144,18 @@ export class CoreBetterAuthMiddleware implements NestMiddleware {
|
|
|
143
144
|
|
|
144
145
|
// Strategy 2: Try JWT from cookie (for JWT mode when frontend stores JWT as cookie)
|
|
145
146
|
// In JWT mode (cookies=false), the frontend may store the JWT in a cookie
|
|
146
|
-
// (
|
|
147
|
+
// (`lt-jwt-token`, `<COOKIE_PREFIX>-jwt-token` with a prefix) instead of sending it as an Authorization header.
|
|
147
148
|
// This bridges the gap between cookie-based frontend storage and JWT verification.
|
|
148
149
|
if (!req.user && !req.headers.authorization && this.betterAuthService.isJwtEnabled()) {
|
|
149
150
|
try {
|
|
150
|
-
// Try parsed cookies first, then raw header (cookie-parser may not have run yet)
|
|
151
|
-
|
|
151
|
+
// Try parsed cookies first, then raw header (cookie-parser may not have run yet). The name follows
|
|
152
|
+
// COOKIE_PREFIX like the frontend's (`<prefix>-jwt-token`, else `lt-jwt-token`; 12.11.2).
|
|
153
|
+
const jwtCookieName = resolveJwtCookieName();
|
|
154
|
+
let jwtFromCookie = req.cookies?.[jwtCookieName];
|
|
152
155
|
if (!jwtFromCookie && req.headers.cookie) {
|
|
153
|
-
const match = req.headers.cookie.match(
|
|
156
|
+
const match = req.headers.cookie.match(
|
|
157
|
+
new RegExp(`(?:^|;\\s*)${jwtCookieName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}=([^;]+)`),
|
|
158
|
+
);
|
|
154
159
|
if (match) {
|
|
155
160
|
jwtFromCookie = decodeURIComponent(match[1]);
|
|
156
161
|
}
|
|
@@ -141,7 +141,7 @@ A hint tells a connected client that pulling is worthwhile; sync works without t
|
|
|
141
141
|
stream is registered in the same registry and re-checked at once on an invalidation naming the caller or their
|
|
142
142
|
tenant, and otherwise before the first hint after `graphQl.subscriptionRevalidationMs`.
|
|
143
143
|
- **In place (12.11.0)** when the stream was opened with a Better-Auth credential — the session cookie, a bearer
|
|
144
|
-
session token or Better-Auth JWT, the `lt-jwt-token`
|
|
144
|
+
session token or Better-Auth JWT, the JWT cookie (`lt-jwt-token`, `<COOKIE_PREFIX>-jwt-token` with a prefix): the re-check runs that credential again
|
|
145
145
|
(`createHttpStreamReauthenticator()`) and the tenant resolution, like a WebSocket's. Unchanged rights keep the
|
|
146
146
|
stream open and the hint is delivered without a reconnect; changed user id, roles, verification or tenant scope
|
|
147
147
|
close it (`Closing SSE hint stream of user …: User authorization changed` / `Session no longer valid` /
|