@lenne.tech/nuxt-extensions 4.0.5 → 4.0.6
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 +22 -0
- package/README.md +13 -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 +38 -1
- package/dist/runtime/types/auth.d.ts +14 -0
- package/package.json +4 -4
package/CLAUDE.md
CHANGED
|
@@ -303,6 +303,28 @@ unchanged. That token is the session token, the value the API keeps in the httpO
|
|
|
303
303
|
`'cookie'` that left JWT mode, and the JWT the client had just stored was no longer sent: the
|
|
304
304
|
app then depended on a session cookie, which JWT mode exists not to rely on. Never let another
|
|
305
305
|
user keep JWT mode: the stored JWT is the previous user's.
|
|
306
|
+
- **`validateSession()` keeps the mode for the signed-in user while a JWT is stored** (since
|
|
307
|
+
4.0.6; ng-base does the same since 22.0.0). Up to 4.0.5 it set `'cookie'` and fetched a new JWT,
|
|
308
|
+
so after every page load in JWT mode requests went out without the bearer until `/iam/token`
|
|
309
|
+
answered; the starter's E2E measured `two-factor/disable` without an `Authorization` header.
|
|
310
|
+
With `cookies: false` those requests, and the cookie-only `/iam/token` itself, then worked only
|
|
311
|
+
because nest-server reads the JWT cookie when no bearer comes, and before 12.11.2 it ignored
|
|
312
|
+
`COOKIE_PREFIX` there. Another user, or JWT mode without a stored JWT, starts on `'cookie'`.
|
|
313
|
+
**The `/iam/token` request on every page load stays, in JWT mode too.** With `cookies: false`
|
|
314
|
+
nest-server sets no session cookie, so `/iam/token` can only be paid for by a JWT cookie that is
|
|
315
|
+
still valid, and an expired JWT cannot be renewed at all; ng-base renews before sending
|
|
316
|
+
(`currentJwt()`), this module has nothing like it. Asking `/iam/token` only in cookie mode was
|
|
317
|
+
tried during 4.0.6 and ended every such sign-in with its first JWT, however often the page was
|
|
318
|
+
loaded. `test/validate-session-mode.test.ts` holds this.
|
|
319
|
+
- **`validateSession()` signs out a cached user the API has no session for** (since 4.0.6): a
|
|
320
|
+
`get-session` that ANSWERED without a session (not pending, no `error`), outside JWT mode with a
|
|
321
|
+
stored JWT, and confirmed by a direct `get-session` (`probeSession()`, the 401 interceptor's
|
|
322
|
+
rules: 401/403 or an empty 200 is dead, 5xx/429/network decides nothing) → `clearUser()`,
|
|
323
|
+
`false`. Up to 4.0.5 the cached user was trusted there: a project's API session had expired, the
|
|
324
|
+
page greeted the user by name, and every protected call failed (its API answered 403, so the
|
|
325
|
+
interceptor never fired either). **Never drop the confirming probe**: Better Auth's session atom
|
|
326
|
+
can hold a stale empty answer after a sign-in that does not refetch it, and a page load must not
|
|
327
|
+
undo a sign-in. `clearUser()`, not `signOut()`: an expired session deletes no offline-sync data.
|
|
306
328
|
- **`useLtAuthClient().twoFactor.verify*` / `enable` / `disable`, `changePassword` and
|
|
307
329
|
`signIn.social` strip a non-JWT `token` from the answer**, and `authenticateWithPasskey()`
|
|
308
330
|
returns no `session`. Keep all of them: application code that never receives the session token
|
package/README.md
CHANGED
|
@@ -551,6 +551,19 @@ or `exposeTokenInBody`): the JWT of the session that is valid after the answer.
|
|
|
551
551
|
(same `id`), as `setUser({ ...user.value, twoFactorEnabled: true })` after turning 2FA on does.
|
|
552
552
|
Any other user starts on the cookie session (since 4.0.5; before, every call without a mode
|
|
553
553
|
meant cookie mode, and a settings page in JWT mode stopped sending its JWT).
|
|
554
|
+
- **`validateSession()` keeps the auth mode of the signed-in user** (since 4.0.6). After a page
|
|
555
|
+
load in JWT mode the stored JWT goes out with the first request, while a new one is fetched from
|
|
556
|
+
`/iam/token` in the background. Up to 4.0.5 every page load switched to cookie mode until
|
|
557
|
+
`/iam/token` answered, and requests in that window went out without the JWT. Another user, or
|
|
558
|
+
JWT mode with no JWT stored, starts on the cookie session.
|
|
559
|
+
- **`validateSession()` signs out a user the API no longer has a session for** (since 4.0.6).
|
|
560
|
+
When `get-session` answers without a session while `lt-auth-state` still holds a user (the
|
|
561
|
+
session expired or was deleted on the server), it calls `clearUser()` and returns `false`, after
|
|
562
|
+
a second, direct `get-session` confirmed it. Up to 4.0.5 it returned `true` for the cached user:
|
|
563
|
+
the page showed the user as signed in while every protected request failed, until one of them
|
|
564
|
+
answered 401. JWT mode with a stored JWT keeps the user, and so does an answer that is not a
|
|
565
|
+
verdict (a timeout, a network error, a 5xx). Unsent offline-sync changes stay, as after any
|
|
566
|
+
expired session.
|
|
554
567
|
- **`useLtAuthClient().twoFactor.verifyTotp()`, `verifyBackupCode()`, `enable()`, `disable()`
|
|
555
568
|
and `changePassword()` return no session token.** A JWT in the answer stays, and the client
|
|
556
569
|
stores it in `lt-jwt-token` (since 4.0.5); the auth mode is left as it is. From nest-server
|
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.6";
|
|
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.6";
|
|
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";
|
|
@@ -169,6 +169,36 @@ export function useLtAuth() {
|
|
|
169
169
|
}
|
|
170
170
|
return merged;
|
|
171
171
|
}
|
|
172
|
+
async function probeSession() {
|
|
173
|
+
const controller = new AbortController();
|
|
174
|
+
let timer;
|
|
175
|
+
const timeout = new Promise((resolve) => {
|
|
176
|
+
timer = setTimeout(() => {
|
|
177
|
+
controller.abort();
|
|
178
|
+
resolve(null);
|
|
179
|
+
}, VALIDATE_SESSION_TIMEOUT_MS);
|
|
180
|
+
});
|
|
181
|
+
const verdict = (async () => {
|
|
182
|
+
try {
|
|
183
|
+
const response = await fetchWithAuth(`${getLtApiBase()}/get-session`, { method: "GET", signal: controller.signal });
|
|
184
|
+
if (response.status === 401 || response.status === 403) {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
if (!response.ok) {
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
const data = await response.json().catch(() => null);
|
|
191
|
+
return Boolean(data && (data.user || data.session));
|
|
192
|
+
} catch {
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
})();
|
|
196
|
+
try {
|
|
197
|
+
return await Promise.race([verdict, timeout]);
|
|
198
|
+
} finally {
|
|
199
|
+
clearTimeout(timer);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
172
202
|
async function validateSession() {
|
|
173
203
|
if (import.meta.server) {
|
|
174
204
|
return !!resolvedAuthState.value?.user;
|
|
@@ -196,12 +226,19 @@ export function useLtAuth() {
|
|
|
196
226
|
});
|
|
197
227
|
}
|
|
198
228
|
if (session.value.data?.user) {
|
|
199
|
-
|
|
229
|
+
const sessionUser = mergeSessionUser(session.value.data.user);
|
|
230
|
+
const keepsJwt = isJwtMode.value && !!jwtToken.value && user.value?.id === sessionUser.id;
|
|
231
|
+
setUser(sessionUser, keepsJwt ? "jwt" : "cookie");
|
|
200
232
|
switchToJwtMode().catch(() => {
|
|
201
233
|
});
|
|
202
234
|
return true;
|
|
203
235
|
}
|
|
204
236
|
if (resolvedAuthState.value?.user) {
|
|
237
|
+
const answeredWithoutSession = !session.value.isPending && !session.value.error;
|
|
238
|
+
if (answeredWithoutSession && !(isJwtMode.value && jwtToken.value) && await probeSession() === false) {
|
|
239
|
+
clearUser();
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
205
242
|
switchToJwtMode().catch(() => {
|
|
206
243
|
});
|
|
207
244
|
return true;
|
|
@@ -367,6 +367,20 @@ export interface UseLtAuthReturn {
|
|
|
367
367
|
}>(params: NoStrayCredential<T, 'password'>, options?: unknown) => Promise<unknown>;
|
|
368
368
|
};
|
|
369
369
|
switchToJwtMode: () => Promise<boolean>;
|
|
370
|
+
/**
|
|
371
|
+
* Re-validates the session (app start, hard reload) through `get-session` and merges the
|
|
372
|
+
* session user onto the cached one. `true` while signed in.
|
|
373
|
+
*
|
|
374
|
+
* The signed-in user keeps JWT mode while a JWT is stored, and the stored JWT is sent while a
|
|
375
|
+
* new one is fetched in the background (since 4.0.6; before, every page load switched to cookie
|
|
376
|
+
* mode until the new JWT came). Another user, or JWT mode without a stored JWT, starts on the
|
|
377
|
+
* cookie session.
|
|
378
|
+
*
|
|
379
|
+
* When the API has no session for the cached user any more (confirmed by a direct
|
|
380
|
+
* `get-session`), the user is cleared and the result is `false` (since 4.0.6; before, the cached
|
|
381
|
+
* user counted as signed in). JWT mode with a stored JWT, a timeout and a failed request keep
|
|
382
|
+
* the user.
|
|
383
|
+
*/
|
|
370
384
|
validateSession: () => Promise<boolean>;
|
|
371
385
|
passkey?: unknown;
|
|
372
386
|
/**
|
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.6",
|
|
4
4
|
"description": "Reusable Nuxt 4 composables, components, and Better-Auth integration for lenne.tech projects",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -112,7 +112,7 @@
|
|
|
112
112
|
"devDependencies": {
|
|
113
113
|
"@better-auth/passkey": "1.7.19",
|
|
114
114
|
"@nuxt/module-builder": "1.0.4",
|
|
115
|
-
"@nuxt/schema": "4.
|
|
115
|
+
"@nuxt/schema": "4.7.0",
|
|
116
116
|
"@nuxt/ui": "4.13.1",
|
|
117
117
|
"@playwright/test": "1.65.1",
|
|
118
118
|
"@types/node": "26.6.6",
|
|
@@ -122,7 +122,7 @@
|
|
|
122
122
|
"cross-spawn": "7.0.6",
|
|
123
123
|
"fake-indexeddb": "6.2.8",
|
|
124
124
|
"happy-dom": "21.0.4",
|
|
125
|
-
"nuxt": "4.
|
|
125
|
+
"nuxt": "4.7.0",
|
|
126
126
|
"oxfmt": "0.80.0",
|
|
127
127
|
"oxlint": "1.95.0",
|
|
128
128
|
"oxlint-tsgolint": "7.0.2008",
|
|
@@ -151,5 +151,5 @@
|
|
|
151
151
|
"node": ">= 22",
|
|
152
152
|
"pnpm": "^11.0.0"
|
|
153
153
|
},
|
|
154
|
-
"packageManager": "pnpm@11.
|
|
154
|
+
"packageManager": "pnpm@11.29.0+sha512.d913f9b37cd5fe6780052e809774edabb7bdcf69a6e6d9b8fd3b38bc052fa8a7d891b6c201a38fb504a07ffce2e5e8c262ef54fb8f57db62f22d353a30bc8a96"
|
|
155
155
|
}
|