@lenne.tech/nuxt-extensions 4.0.3 → 4.0.4
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.md +12 -0
- package/README.md +7 -0
- package/dist/module.d.mts +1 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +1 -1
- package/dist/runtime/composables/auth/use-lt-auth.js +12 -4
- package/dist/runtime/lib/auth-state.d.ts +33 -1
- package/dist/runtime/lib/auth-state.js +25 -0
- package/package.json +3 -3
package/CLAUDE.md
CHANGED
|
@@ -157,6 +157,18 @@ renewed an expired JWT. Do not write a third one; a caller with its own state pa
|
|
|
157
157
|
- **The JWT comes from `auth.basePath`.** Without an argument, `ltAuthFetch`, `createLtAuthFetch()`
|
|
158
158
|
and `attemptLtJwtSwitch()` read it from the runtime config. `requestLtJwt()` is the only place a
|
|
159
159
|
JWT is fetched, `useLtAuth().switchToJwtMode()` included.
|
|
160
|
+
- **An API that reports `jwt: false` in `/features` is never asked for a JWT.** nest-server with
|
|
161
|
+
`betterAuth.jwt: false` answers `/token` with 404; before this, every sign-in, session check and
|
|
162
|
+
401 cost one 404 with a console error. `fetchFeatures()` hands its request to
|
|
163
|
+
`noteLtJwtServedBy()`, and `requestLtJwt()` returns `null` without a request once the answer said
|
|
164
|
+
`false`. It awaits a features request still in flight (at app start `validateSession()` asks for
|
|
165
|
+
the JWT while it is). Features an SSR render fetched (the starter's register page) reach the
|
|
166
|
+
client in the payload, and the client fetches none of its own: `useLtAuth()` then hands the
|
|
167
|
+
payload state to `noteLtJwtServedByPayload()`, which counts only while nothing in the tab was
|
|
168
|
+
noted, so a second `useLtAuth()` call never replaces a request in flight. Client only; a missing
|
|
169
|
+
flag or a failed request keeps today's behaviour.
|
|
170
|
+
No module option on purpose: the API is the one source, and a second switch in the app could
|
|
171
|
+
disagree with it. `test/jwt-disabled-api.test.ts` holds this.
|
|
160
172
|
|
|
161
173
|
## AI Assistant Flow
|
|
162
174
|
|
package/README.md
CHANGED
|
@@ -645,6 +645,13 @@ the AI composables and offline sync) run through one implementation.
|
|
|
645
645
|
- **The JWT comes from `auth.basePath`.** Without an argument, `ltAuthFetch`, `createLtAuthFetch()`
|
|
646
646
|
and `attemptLtJwtSwitch()` read it from the module config; they used to fetch it from `/iam`
|
|
647
647
|
whatever was configured. A path passed explicitly still wins.
|
|
648
|
+
- **An API without JWT is not asked for one.** When `GET <basePath>/features` reports `jwt: false`
|
|
649
|
+
(nest-server with `betterAuth.jwt: false`, whose `/token` answers 404), neither a sign-in, a
|
|
650
|
+
session check nor a 401 requests `/token`: the app stays on the cookie session, and a 401 reaches
|
|
651
|
+
the caller unchanged. Nothing to configure in the app; the features request `useLtAuth()` makes on
|
|
652
|
+
its first client-side call decides, and a JWT request at app start waits for it. Features a page
|
|
653
|
+
fetched during SSR (`await fetchFeatures()` in `import.meta.server`) count the same, from the
|
|
654
|
+
payload. An API that reports `jwt: true`, or no `jwt` at all, is asked as before.
|
|
648
655
|
|
|
649
656
|
#### Server-side rendering: backend calls are anonymous
|
|
650
657
|
|
package/dist/module.d.mts
CHANGED
|
@@ -3,7 +3,7 @@ import { LtExtensionsModuleOptions } from '../dist/runtime/types/index.js';
|
|
|
3
3
|
export * from '../dist/runtime/types/index.js';
|
|
4
4
|
|
|
5
5
|
declare const name = "@lenne.tech/nuxt-extensions";
|
|
6
|
-
declare const version = "4.0.
|
|
6
|
+
declare const version = "4.0.4";
|
|
7
7
|
declare const configKey = "ltExtensions";
|
|
8
8
|
declare const DEFAULT_LT_AUTH_STATE_COOKIE = "lt-auth-state";
|
|
9
9
|
declare const DEFAULT_LT_JWT_TOKEN_COOKIE = "lt-jwt-token";
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { pathToFileURL } from 'node:url';
|
|
|
3
3
|
import { SECURITY_TXT_DEFAULT_VALID_DAYS, SECURITY_TXT_DEFAULT_LANGUAGES, SECURITY_TXT_DEFAULT_CONTACT, SECURITY_TXT_PATH } from '../dist/runtime/server/lib/security-txt.js';
|
|
4
4
|
|
|
5
5
|
const name = "@lenne.tech/nuxt-extensions";
|
|
6
|
-
const version = "4.0.
|
|
6
|
+
const version = "4.0.4";
|
|
7
7
|
const configKey = "ltExtensions";
|
|
8
8
|
const DEFAULT_LT_AUTH_STATE_COOKIE = "lt-auth-state";
|
|
9
9
|
const DEFAULT_LT_JWT_TOKEN_COOKIE = "lt-jwt-token";
|
|
@@ -7,6 +7,8 @@ import {
|
|
|
7
7
|
getLtAuthCookieNames,
|
|
8
8
|
getLtJwtToken,
|
|
9
9
|
isLtJwtShaped,
|
|
10
|
+
noteLtJwtServedBy,
|
|
11
|
+
noteLtJwtServedByPayload,
|
|
10
12
|
requestLtJwt,
|
|
11
13
|
resolveLtAuthState,
|
|
12
14
|
toLtStoredAuthState,
|
|
@@ -211,7 +213,9 @@ export function useLtAuth() {
|
|
|
211
213
|
async function fetchFeatures() {
|
|
212
214
|
try {
|
|
213
215
|
const apiBase = getLtApiBase();
|
|
214
|
-
const
|
|
216
|
+
const request = $fetch(`${apiBase}/features`);
|
|
217
|
+
noteLtJwtServedBy(request);
|
|
218
|
+
const result = await request;
|
|
215
219
|
if (result) {
|
|
216
220
|
features.value = result;
|
|
217
221
|
featuresFetched.value = true;
|
|
@@ -520,9 +524,13 @@ export function useLtAuth() {
|
|
|
520
524
|
verifyBackupCode: verifyingTwoFactor("verifyBackupCode"),
|
|
521
525
|
verifyTotp: verifyingTwoFactor("verifyTotp")
|
|
522
526
|
};
|
|
523
|
-
if (import.meta.client
|
|
524
|
-
featuresFetched.value
|
|
525
|
-
|
|
527
|
+
if (import.meta.client) {
|
|
528
|
+
if (!featuresFetched.value) {
|
|
529
|
+
featuresFetched.value = true;
|
|
530
|
+
void fetchFeatures();
|
|
531
|
+
} else {
|
|
532
|
+
noteLtJwtServedByPayload(features.value);
|
|
533
|
+
}
|
|
526
534
|
}
|
|
527
535
|
return {
|
|
528
536
|
// Auth state
|
|
@@ -349,7 +349,39 @@ export declare function setLtAuthMode(mode: LtAuthMode): void;
|
|
|
349
349
|
*/
|
|
350
350
|
export declare function getLtApiBase(basePath?: string): string;
|
|
351
351
|
/**
|
|
352
|
-
* `GET <auth>/
|
|
352
|
+
* Learn from a `GET <auth>/features` request whether the API hands out JWTs at all (its `jwt` flag).
|
|
353
|
+
*
|
|
354
|
+
* nest-server with `betterAuth.jwt: false` reports `jwt: false`, and its `/token` answers 404. Once
|
|
355
|
+
* the API said so, {@link requestLtJwt} asks no more, so a cookie-only API sees no `/token` request
|
|
356
|
+
* after a sign-in, a session check or a 401. An answer without the flag (an older API) or a failed
|
|
357
|
+
* request changes nothing: the JWT is fetched as before, and a failed request keeps what an
|
|
358
|
+
* earlier answer said.
|
|
359
|
+
*
|
|
360
|
+
* INTERNAL — called by `useLtAuth().fetchFeatures()` with its request. Not part of the public API.
|
|
361
|
+
*/
|
|
362
|
+
export declare function noteLtJwtServedBy(featuresRequest: Promise<unknown>): void;
|
|
363
|
+
/**
|
|
364
|
+
* Learn the `jwt` flag from features an SSR render already fetched.
|
|
365
|
+
*
|
|
366
|
+
* A page that awaits `fetchFeatures()` on the server (nuxt-base-starter's register page, against a
|
|
367
|
+
* hydration mismatch) sends them in the payload, and the client then fetches none of its own: without
|
|
368
|
+
* this, a cookie-only API got `/token` requests in that tab after all. Taken only while nothing in
|
|
369
|
+
* this tab was noted yet, so a second `useLtAuth()` call never replaces a features request still in
|
|
370
|
+
* flight, and a later live answer wins.
|
|
371
|
+
*
|
|
372
|
+
* INTERNAL — called by `useLtAuth()` on the client. Not part of the public API.
|
|
373
|
+
*/
|
|
374
|
+
export declare function noteLtJwtServedByPayload(features: Record<string, unknown>): void;
|
|
375
|
+
/**
|
|
376
|
+
* Forget what any features request said about JWT.
|
|
377
|
+
*
|
|
378
|
+
* INTERNAL — test-only. Module-scope state survives every test in a file that does not call
|
|
379
|
+
* `vi.resetModules()`. Production code must never call this.
|
|
380
|
+
*/
|
|
381
|
+
export declare function resetLtJwtServedState(): void;
|
|
382
|
+
/**
|
|
383
|
+
* `GET <auth>/token` with the session cookie: a fresh JWT, or `null` (refused, not JWT-shaped,
|
|
384
|
+
* offline, or an API whose `/features` said `jwt: false`, see {@link noteLtJwtServedBy}).
|
|
353
385
|
*
|
|
354
386
|
* INTERNAL — the one place a JWT is fetched: {@link attemptLtJwtSwitch}, the 401 recovery of
|
|
355
387
|
* {@link createLtAuthFetch} and `useLtAuth().switchToJwtMode()` all go through it. Not part of the
|
|
@@ -251,7 +251,32 @@ export function getLtApiBase(basePath) {
|
|
|
251
251
|
}
|
|
252
252
|
return buildLtApiUrl(basePath || "/iam");
|
|
253
253
|
}
|
|
254
|
+
let ltJwtServed;
|
|
255
|
+
export function noteLtJwtServedBy(featuresRequest) {
|
|
256
|
+
if (!import.meta.client) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
const before = ltJwtServed;
|
|
260
|
+
ltJwtServed = featuresRequest.then(
|
|
261
|
+
(features) => {
|
|
262
|
+
const jwt = features?.jwt;
|
|
263
|
+
return typeof jwt === "boolean" ? jwt : void 0;
|
|
264
|
+
},
|
|
265
|
+
() => before
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
export function noteLtJwtServedByPayload(features) {
|
|
269
|
+
if (import.meta.client && !ltJwtServed) {
|
|
270
|
+
noteLtJwtServedBy(Promise.resolve(features));
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
export function resetLtJwtServedState() {
|
|
274
|
+
ltJwtServed = void 0;
|
|
275
|
+
}
|
|
254
276
|
export async function requestLtJwt(basePath) {
|
|
277
|
+
if (import.meta.client && ltJwtServed && await ltJwtServed === false) {
|
|
278
|
+
return null;
|
|
279
|
+
}
|
|
255
280
|
try {
|
|
256
281
|
const response = await fetch(`${getLtApiBase(basePath)}/token`, {
|
|
257
282
|
credentials: "include",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lenne.tech/nuxt-extensions",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.4",
|
|
4
4
|
"description": "Reusable Nuxt 4 composables, components, and Better-Auth integration for lenne.tech projects",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -117,7 +117,7 @@
|
|
|
117
117
|
"@playwright/test": "1.65.1",
|
|
118
118
|
"@types/node": "26.6.6",
|
|
119
119
|
"@vitest/coverage-v8": "5.1.1",
|
|
120
|
-
"@vue/server-renderer": "3.5.
|
|
120
|
+
"@vue/server-renderer": "3.5.46",
|
|
121
121
|
"better-auth": "1.7.19",
|
|
122
122
|
"cross-spawn": "7.0.6",
|
|
123
123
|
"fake-indexeddb": "6.2.8",
|
|
@@ -125,7 +125,7 @@
|
|
|
125
125
|
"nuxt": "4.6.4",
|
|
126
126
|
"oxfmt": "0.79.0",
|
|
127
127
|
"oxlint": "1.94.0",
|
|
128
|
-
"oxlint-tsgolint": "7.0.
|
|
128
|
+
"oxlint-tsgolint": "7.0.2008",
|
|
129
129
|
"reka-ui": "2.11.0",
|
|
130
130
|
"semver": "7.8.6",
|
|
131
131
|
"tailwindcss": "4.3.5",
|