@lenne.tech/nuxt-extensions 4.0.2 → 4.0.3

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 CHANGED
@@ -25,8 +25,8 @@ src/
25
25
 
26
26
  | Composable | Purpose |
27
27
  |-----------|---------|
28
- | `useLtAuth()` | Authentication state, login, logout, session management, password change + reset |
29
- | `useLtAuthClient()` | Raw Better Auth client access (`twoFactor.*`, `admin.*`, `passkey`) |
28
+ | `useLtAuth()` | Authentication state, login (password, passkey, social provider), logout, session management, password change + reset |
29
+ | `useLtAuthClient()` | Raw Better Auth client access (`twoFactor.*`, `admin.*`, `passkey`, `signIn.social`) |
30
30
  | `useSystemSetup()` | First-admin setup flow: status, HTTP-setup release + setup token (nest-server >= 12.4.0) |
31
31
  | `useLtTusUpload()` | TUS resumable file uploads |
32
32
  | `useLtFile()` | File utilities (size formatting; file links on the API, the public URL also during SSR) |
@@ -128,6 +128,7 @@ of `useLtFile()` use the browser's address during SSR too.
128
128
  - Protected-route gating is the consumer's own middleware (see "Custom Auth Middleware Pattern" below); the module only registers the optional `lt-system-setup` middleware
129
129
  - Passkey (WebAuthn) support via `@better-auth/passkey` peer dependency
130
130
  - 2FA (TOTP) support built-in
131
+ - Sign-in through a social provider the API configured (`signIn.social`, see below)
131
132
 
132
133
  ### Auth Flow
133
134
 
@@ -279,9 +280,9 @@ unchanged. That token is the session token, the value the API keeps in the httpO
279
280
  - **`setUser(user, 'jwt')` without a stored JWT falls back to `'cookie'`** and fetches the JWT.
280
281
  Without that fallback, the refusal above would turn a hand-written 2FA page into a sign-in that
281
282
  sends no credentials at all.
282
- - **`useLtAuthClient().twoFactor.verify*` strips a non-JWT `token` from the answer**, and
283
- `authenticateWithPasskey()` returns no `session`. Keep both: application code that never
284
- receives the session token cannot store it.
283
+ - **`useLtAuthClient().twoFactor.verify*` and `signIn.social` strip a non-JWT `token` from the
284
+ answer**, and `authenticateWithPasskey()` returns no `session`. Keep all three: application code
285
+ that never receives the session token cannot store it.
285
286
 
286
287
  ### How Auth Cookies Work:
287
288
  1. `setUser()` writes the cookie via both `useCookie().value` (for SSR sync) and `document.cookie` (for immediate availability)
@@ -327,6 +328,51 @@ export default defineNuxtRouteMiddleware((to) => {
327
328
  });
328
329
  ```
329
330
 
331
+ ## Social Sign-In (`signIn.social`, since 4.0.3)
332
+
333
+ `useLtAuth().signIn.social(params)` signs in through a provider the API configured
334
+ (`betterAuth.socialProviders` in nest-server; first use: Microsoft Entra ID as single sign-on).
335
+ `GET /iam/features` lists the enabled providers as `socialProviders`, which `useLtAuth().features`
336
+ holds. `useLtAuthClient().signIn.social` is the same call without the auth state. Parameters:
337
+ `LtSocialSignInParams` in `runtime/types/auth.ts`.
338
+
339
+ - **Redirect shape (no `idToken`): the page is left.** The answer is the provider's authorization
340
+ URL and Better Auth's client navigates there; nothing is stored. The API's callback sets the
341
+ session cookie and redirects to `callbackURL`, where the user arrives through `validateSession()`.
342
+ - **ID-token shape: signed in at once.** For an app inside a host that already knows the user
343
+ (Microsoft Teams, a native shell). The answer is `{ token, user }`; the wrapper strips the session
344
+ token, and `completeForwardedSignIn()` signs the user in on the cookie session and fetches the
345
+ JWT from `/iam/token`, exactly as after 2FA. `withoutSessionToken` strips only `result.data`, as
346
+ for 2FA: with `throw: true` (as `options` or in `fetchOptions`) the body comes back with the
347
+ token, and a caller's `onSuccess` hook sees the answer before the token is removed.
348
+ - **Silent attempt: `additionalParams: { prompt: 'none' }`.** The provider answers without showing
349
+ anything, and the way back without a provider session is `errorCallbackURL` with
350
+ `?error=login_required` (or `interaction_required`). A page that starts the attempt on load must
351
+ remember per tab that it tried, and must not try after an explicit sign-out; otherwise it loops
352
+ or signs the user straight back in. nuxt-base-starter's login page shows the pattern.
353
+ - **`?error=` is a code; map it, never render the query.** The provider's own codes
354
+ (`access_denied`, `consent_required`, …) and Better Auth's (`signup_disabled`, …) arrive there,
355
+ next to an `error_description` anybody can write into a link.
356
+ - **`callbackURL` / `errorCallbackURL` must be absolute URLs of a trusted origin, never user
357
+ input.** Same reasoning as `redirectTo` below: Better Auth resolves a relative value against the
358
+ API origin, and `trustedOrigins` is the only check on the result. Build both from the app's own
359
+ origin and a fixed path (`appUrl()` in the starters); a deep link goes into their query only after
360
+ `safeRedirectTarget()`.
361
+ - **Nothing is hashed.** No credential travels, so the parameters go through unchanged; the
362
+ wrapper changes only the answer. `test/auth-client-social-sign-in.test.ts`,
363
+ `test/social-sign-in-session.test.ts` and the `signIn.social` case in
364
+ `test/better-auth-contract.test.ts` (real better-auth client, stubbed `fetch`) hold this.
365
+
366
+ **An inline image never reaches the auth state.** Better Auth's Microsoft provider stores the
367
+ profile photo in `user.image` as a `data:` URL. In `lt-auth-state` a few KB of it push the cookie
368
+ past the browser's 4096 bytes, the browser drops it without an error, and the next page load reads
369
+ as a logout (with a silent sign-in on the login page: a loop through app, API and provider). Every
370
+ writer of the auth state goes through `toLtStoredAuthState()` in `lib/auth-state.ts`, which leaves a
371
+ `data:` image out at any size and keeps an `http(s)` URL or a path; `user.value.image` is then
372
+ `undefined`, and an app reads the photo from `GET <basePath>/get-session`. An API that does not need
373
+ the photo sets `disableProfilePhoto: true` on the Microsoft provider. A new writer of the auth state
374
+ uses the same function. `test/auth-state-inline-image.test.ts` emulates the browser's limit.
375
+
330
376
  ## Password Handling: Reset, Change, and Client-Side Hashing
331
377
 
332
378
  **Every password leaves the browser SHA256-hashed.** `auth-client.ts` wraps each Better-Auth
package/README.md CHANGED
@@ -111,7 +111,7 @@ nuxt-extensions release it pins.
111
111
 
112
112
  ## Features
113
113
 
114
- - **Better-Auth Integration** - Login, 2FA, Passkey/WebAuthn support
114
+ - **Better-Auth Integration** - Login, 2FA, Passkey/WebAuthn, sign-in through social providers (SSO)
115
115
  - **Cookie/JWT Dual-Mode** - Automatic fallback from cookies to JWT
116
116
  - **TUS File Upload** - Resumable uploads with pause/resume
117
117
  - **Offline Sync** - Read and write offline, reconcile with the nest-server sync module (opt-in)
@@ -548,6 +548,86 @@ JWT from `/iam/token`.
548
548
  session token.**
549
549
  - **`authenticateWithPasskey()` returns no `session`.**
550
550
 
551
+ #### Sign-in through a social provider
552
+
553
+ `useLtAuth().signIn.social()` (since 4.0.3; `useLtAuthClient().signIn.social()` is the same call
554
+ without the auth state) signs in through a provider the API configured, for example Microsoft
555
+ Entra ID for single sign-on (`betterAuth.socialProviders` in nest-server). `GET /iam/features`
556
+ lists the enabled providers as `socialProviders`; `useLtAuth().features` holds that answer, so a
557
+ login page can show one button per entry.
558
+
559
+ Both shapes go to `POST <basePath>/sign-in/social`:
560
+
561
+ - **Redirect, the usual one.** The answer is the provider's authorization URL, and Better Auth's
562
+ client navigates there: the page is left, and nothing is stored yet. The provider sends the
563
+ browser to the API, which sets the session cookie and redirects to `callbackURL`. The user
564
+ arrives through `validateSession()` on the page behind it.
565
+ - **ID token**, for an app inside a host that already knows the user (Microsoft Teams, a native
566
+ shell). With `idToken` the API answers `{ user }` at once, without navigation. `useLtAuth()` signs
567
+ the user in on the cookie session and fetches the JWT from `/iam/token`, as after 2FA. The
568
+ session token Better Auth puts into that answer is removed, as in the 2FA answers. This covers
569
+ the default `{ data, error }` answer only: with `throw: true` (as `options` or in `fetchOptions`)
570
+ the body comes back unchanged, token included, and an `onSuccess` hook sees the answer before the
571
+ token is removed.
572
+
573
+ ```vue
574
+ <script setup lang="ts">
575
+ const { features, signIn } = useLtAuth();
576
+ const config = useRuntimeConfig();
577
+
578
+ const providers = computed(() => (Array.isArray(features.value.socialProviders) ? features.value.socialProviders : []));
579
+
580
+ // Interactive: the provider shows its account picker.
581
+ async function signInWith(provider: string) {
582
+ await signIn.social({
583
+ additionalParams: { prompt: 'select_account' },
584
+ callbackURL: new URL('/auth/callback', config.public.siteUrl).toString(),
585
+ errorCallbackURL: new URL('/auth/login', config.public.siteUrl).toString(),
586
+ provider,
587
+ });
588
+ }
589
+ </script>
590
+ ```
591
+
592
+ ```vue
593
+ <!-- pages/auth/callback.vue: the session cookie is set, the user is not loaded yet -->
594
+ <script setup lang="ts">
595
+ const { validateSession } = useLtAuth();
596
+
597
+ onMounted(async () => {
598
+ const signedIn = await validateSession();
599
+ await navigateTo(signedIn ? '/app' : '/auth/login', { replace: true });
600
+ });
601
+ </script>
602
+ ```
603
+
604
+ - **A silent attempt is `additionalParams: { prompt: 'none' }`.** The provider answers without
605
+ showing anything: with the session when the user has one there, otherwise through
606
+ `errorCallbackURL` with `?error=login_required` (or `interaction_required`). That way back is the
607
+ only one, so the page behind it must not start the attempt again: remember it per tab, and do
608
+ not try silently after an explicit sign-out, or the user is signed in again at once.
609
+ nuxt-base-starter does both on its login page.
610
+ - **`?error=` on `errorCallbackURL` is a code from the provider or from Better Auth**
611
+ (`access_denied`, `signup_disabled`, …). Map it to your own text. Never render `error_description`
612
+ or anything else from the query: anybody can put text there and send the link around.
613
+ - **`callbackURL` and `errorCallbackURL` must be absolute URLs of a trusted origin, and never come
614
+ from user input.** Better Auth resolves a relative value against the API origin, like
615
+ `redirectTo` (see "Password Change and Reset"), and checks the result against `trustedOrigins`,
616
+ which is all that stands between a value from `route.query` and a redirect to another site. Build
617
+ both from your own origin and a fixed path; a deep link the user should land on afterwards goes
618
+ into their query only after it was validated (nuxt-base-starter: `safeRedirectTarget()`).
619
+ - `additionalParams` applies to this request only, `loginHint` suggests an account, and
620
+ `disableRedirect: true` answers the URL without navigating. `LtSocialSignInParams` documents every
621
+ field.
622
+
623
+ **An inline profile photo is not kept in the auth state.** Better Auth's Microsoft provider stores
624
+ the user's photo in `user.image` as a `data:` URL. In the `lt-auth-state` cookie a few KB of it push
625
+ the cookie past the browser's limit of 4096 bytes; the browser drops it without an error, and the
626
+ next page load reads as a logout. So `useLtAuth().user.value.image` is `undefined` for such a user,
627
+ while an `http(s)` URL or a path stays. Where you render an avatar, read the photo from the session
628
+ answer (`GET <basePath>/get-session`, e.g. `useLtAuthClient().getSession()`). An API that does not
629
+ need the photo sets `disableProfilePhoto: true` on the Microsoft provider.
630
+
551
631
  #### Authenticated requests: `fetchWithAuth` and `ltAuthFetch`
552
632
 
553
633
  `useLtAuth().fetchWithAuth` and `ltAuthFetch` (from `/lib`, also used by the Better-Auth client,
@@ -1207,8 +1287,8 @@ The package works **with or without** `@nuxtjs/i18n`:
1207
1287
 
1208
1288
  | Composable | Description |
1209
1289
  |------------|-------------|
1210
- | `useLtAuth()` | Better-Auth integration with session, passkey, 2FA, password change + reset |
1211
- | `useLtAuthClient()` | Direct access to the Better-Auth client singleton (`twoFactor.*`, `admin.*`, `passkey`) |
1290
+ | `useLtAuth()` | Better-Auth integration with session, passkey, 2FA, social sign-in, password change + reset |
1291
+ | `useLtAuthClient()` | Direct access to the Better-Auth client singleton (`twoFactor.*`, `admin.*`, `passkey`, `signIn.social`) |
1212
1292
  | `useLtErrorTranslation()` | Translate backend error codes to user-friendly messages |
1213
1293
  | `useLtTusUpload()` | TUS protocol file uploads with pause/resume |
1214
1294
  | `useLtFile()` | File utilities (size formatting, URLs) |
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.2";
6
+ declare const version = "4.0.3";
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
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "configKey": "ltExtensions",
3
3
  "name": "@lenne.tech/nuxt-extensions",
4
- "version": "4.0.2",
4
+ "version": "4.0.3",
5
5
  "builder": {
6
- "@nuxt/module-builder": "1.0.3",
6
+ "@nuxt/module-builder": "1.0.4",
7
7
  "unbuild": "3.6.1"
8
8
  }
9
9
  }
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.2";
6
+ const version = "4.0.3";
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";
@@ -9,6 +9,7 @@ import {
9
9
  isLtJwtShaped,
10
10
  requestLtJwt,
11
11
  resolveLtAuthState,
12
+ toLtStoredAuthState,
12
13
  warnLtAdminPluginUnserved
13
14
  } from "../../lib/auth-state.js";
14
15
  import { useLtAuthClient } from "../use-lt-auth-client.js";
@@ -45,7 +46,7 @@ export function useLtAuth() {
45
46
  try {
46
47
  const resolved = resolveLtAuthState(document.cookie, stateCookieName);
47
48
  if (resolved?.user && !authState.value?.user) {
48
- authState.value = resolved;
49
+ authState.value = toLtStoredAuthState(resolved);
49
50
  }
50
51
  } catch {
51
52
  }
@@ -99,8 +100,7 @@ export function useLtAuth() {
99
100
  if (mode !== requestedMode && import.meta.client && userData) {
100
101
  void switchToJwtMode();
101
102
  }
102
- const normalised = userData ? { ...userData, image: userData.image ?? void 0 } : null;
103
- const newState = { user: normalised, authMode: mode };
103
+ const newState = toLtStoredAuthState({ user: userData, authMode: mode });
104
104
  if (import.meta.client || userData) {
105
105
  authState.value = newState;
106
106
  }
@@ -128,7 +128,7 @@ export function useLtAuth() {
128
128
  jwtToken.value = token;
129
129
  }
130
130
  if (authState.value && authState.value.authMode !== "jwt") {
131
- authState.value = { ...authState.value, authMode: "jwt" };
131
+ authState.value = toLtStoredAuthState({ ...authState.value, authMode: "jwt" });
132
132
  }
133
133
  }
134
134
  async function switchToJwtMode() {
@@ -245,6 +245,22 @@ export function useLtAuth() {
245
245
  } finally {
246
246
  isLoading.value = false;
247
247
  }
248
+ },
249
+ /**
250
+ * Sign in through a social provider the API configured. A redirect answer carries no user and
251
+ * leaves the page: the user arrives with `validateSession()` on the page the provider sends the
252
+ * browser back to. An ID-token answer carries the user and is completed here, see
253
+ * `completeForwardedSignIn`.
254
+ */
255
+ social: async (params, options) => {
256
+ isLoading.value = true;
257
+ try {
258
+ const result = await authClient.signIn.social(params, options);
259
+ await completeForwardedSignIn(result);
260
+ return result;
261
+ } finally {
262
+ isLoading.value = false;
263
+ }
248
264
  }
249
265
  };
250
266
  const signUp = {
@@ -475,7 +491,7 @@ export function useLtAuth() {
475
491
  isLoading.value = false;
476
492
  }
477
493
  }
478
- async function completeTwoFactorSignIn(result) {
494
+ async function completeForwardedSignIn(result) {
479
495
  const answer = result;
480
496
  const data = answer?.data;
481
497
  if (answer?.error || !data?.user) {
@@ -493,7 +509,7 @@ export function useLtAuth() {
493
509
  isLoading.value = true;
494
510
  try {
495
511
  const result = await authClient.twoFactor[method](params, options);
496
- await completeTwoFactorSignIn(result);
512
+ await completeForwardedSignIn(result);
497
513
  return result;
498
514
  } finally {
499
515
  isLoading.value = false;
@@ -35,7 +35,7 @@
35
35
  * source-level half so a whitelist rebuild is visible in review. If you add a wrapper that
36
36
  * hashes something, add it to both.
37
37
  */
38
- import type { LtAuthClientConfig } from '../types/index.js';
38
+ import type { LtAuthClientConfig, LtSocialSignInParams } from '../types/index.js';
39
39
  /**
40
40
  * Register additional Better Auth plugins before auth client initialization.
41
41
  *
@@ -626,6 +626,18 @@ export declare function createLtAuthClient(config?: LtAuthClientConfig): {
626
626
  * @see https://www.better-auth.com/docs/plugins/passkey
627
627
  */
628
628
  passkey: any;
629
+ /**
630
+ * Sign in through a social provider the API configured (`betterAuth.socialProviders` in
631
+ * nest-server). No password is involved, so the parameters go through as they are,
632
+ * `additionalParams` included (`{ prompt: 'none' }` asks the provider for a silent sign-in).
633
+ *
634
+ * Without `idToken` Better-Auth answers with the provider's authorization URL and its
635
+ * client navigates there. With `idToken` it answers `{ token, user }` at once; that token
636
+ * is the session token, removed here like in the 2FA answers, see
637
+ * {@link withoutSessionToken}.
638
+ * @see https://www.better-auth.com/docs/authentication/social-sign-in
639
+ */
640
+ social: (params: LtSocialSignInParams, options?: unknown) => Promise<any>;
629
641
  };
630
642
  signOut: <FetchOptions extends import("better-auth").ClientFetchOption<Partial<{
631
643
  callbackURL?: string | undefined;
@@ -188,7 +188,19 @@ export function createLtAuthClient(config = {}) {
188
188
  * Sign in with passkey (pass through to base client - provided by passkeyClient plugin)
189
189
  * @see https://www.better-auth.com/docs/plugins/passkey
190
190
  */
191
- passkey: baseClient.signIn.passkey
191
+ passkey: baseClient.signIn.passkey,
192
+ /**
193
+ * Sign in through a social provider the API configured (`betterAuth.socialProviders` in
194
+ * nest-server). No password is involved, so the parameters go through as they are,
195
+ * `additionalParams` included (`{ prompt: 'none' }` asks the provider for a silent sign-in).
196
+ *
197
+ * Without `idToken` Better-Auth answers with the provider's authorization URL and its
198
+ * client navigates there. With `idToken` it answers `{ token, user }` at once; that token
199
+ * is the session token, removed here like in the 2FA answers, see
200
+ * {@link withoutSessionToken}.
201
+ * @see https://www.better-auth.com/docs/authentication/social-sign-in
202
+ */
203
+ social: async (params, options) => withoutSessionToken(await baseClient.signIn.social(params, options))
192
204
  },
193
205
  // Explicitly pass through signOut (not captured by spread operator)
194
206
  signOut: baseClient.signOut,
@@ -11,7 +11,7 @@
11
11
  *
12
12
  * The state is persisted in cookies for SSR compatibility.
13
13
  */
14
- import type { LtAuthMode, LtAuthState } from '../types/index.js';
14
+ import type { LtAuthMode, LtAuthState, LtUserInput } from '../types/index.js';
15
15
  /** Default name of the auth-state cookie. Used when the module config has not been resolved yet. */
16
16
  export declare const LT_AUTH_STATE_COOKIE_DEFAULT = "lt-auth-state";
17
17
  /** Default name of the JWT-token cookie. Used when the module config has not been resolved yet. */
@@ -262,6 +262,26 @@ export declare function resolveLtPublicApiBaseUrl(): {
262
262
  baseUrl: string;
263
263
  missing: boolean;
264
264
  };
265
+ /**
266
+ * The auth state as it is stored: in the `lt-auth-state` cookie, in the `useCookie` ref Nuxt
267
+ * serialises into that cookie (also during SSR), and therefore in `useLtAuth().user`. Every writer
268
+ * of the auth state goes through this function, so they all store the same thing.
269
+ *
270
+ * - `image: null` (Better-Auth's "no picture") becomes `undefined`: readers have one empty case.
271
+ * - An inline image (a `data:` URL) is left out, whatever its size. Better-Auth's Microsoft provider
272
+ * stores the profile photo as one unless the API sets `disableProfilePhoto`, and a few KB of it
273
+ * push the cookie past the browser's limit of 4096 bytes. The browser drops such a cookie without
274
+ * an error, and the next page load finds a signed-in user signed out. An app that shows the photo
275
+ * reads it from the session answer (`GET <basePath>/get-session`).
276
+ * - An `http(s)` URL or a path stays as it is, and so does every other field.
277
+ *
278
+ * INTERNAL: used by `useLtAuth()` and {@link setLtAuthMode}. Not part of the public API (absent
279
+ * from the barrels and auto-imports).
280
+ */
281
+ export declare function toLtStoredAuthState(state: {
282
+ authMode: LtAuthMode;
283
+ user: LtUserInput | null;
284
+ }): LtAuthState;
265
285
  /**
266
286
  * Get the current auth mode from cookie
267
287
  */
@@ -147,6 +147,17 @@ export function resolveLtPublicApiBaseUrl() {
147
147
  const publicUrl = pub.apiUrl || pub.ltExtensions?.auth?.baseURL || "";
148
148
  return { baseUrl: stripTrailingSlashes(publicUrl), missing: !publicUrl };
149
149
  }
150
+ function isLtInlineImage(value) {
151
+ return typeof value === "string" && /^\s*data:/i.test(value);
152
+ }
153
+ export function toLtStoredAuthState(state) {
154
+ const { user } = state;
155
+ if (user === null || typeof user !== "object") {
156
+ return state;
157
+ }
158
+ const image = user.image ?? void 0;
159
+ return { ...state, user: { ...user, image: isLtInlineImage(image) ? void 0 : image } };
160
+ }
150
161
  export function getLtAuthMode() {
151
162
  if (import.meta.server) return "cookie";
152
163
  return resolveLtAuthState(document.cookie)?.authMode || "cookie";
@@ -223,7 +234,7 @@ export function setLtAuthMode(mode) {
223
234
  try {
224
235
  const { state: stateCookieName } = getLtAuthCookieNames();
225
236
  const existing = resolveLtAuthState(document.cookie, stateCookieName);
226
- const state = { ...existing ?? { user: null }, authMode: mode };
237
+ const state = toLtStoredAuthState({ ...existing ?? { user: null }, authMode: mode });
227
238
  const maxAge = 60 * 60 * 24 * 7;
228
239
  const secure = globalThis.location?.protocol === "https:" ? "; secure" : "";
229
240
  document.cookie = `${stateCookieName}=${encodeURIComponent(JSON.stringify(state))}; path=/; max-age=${maxAge}; samesite=lax${secure}`;
@@ -15,6 +15,6 @@
15
15
  * with the login out of reach. So nothing is redirected; the setup page stays reachable and shows
16
16
  * its notice there (`useSystemSetup().httpInitEnabled === false`).
17
17
  */
18
- import type { RouteMiddleware } from '#app';
18
+ import type { RouteMiddleware } from 'nuxt/app';
19
19
  declare const _default: RouteMiddleware;
20
20
  export default _default;
@@ -16,6 +16,6 @@
16
16
  * Note: This is a client-only plugin (.client.ts) since auth state
17
17
  * management only makes sense in the browser context.
18
18
  */
19
- import type { ObjectPlugin, Plugin } from '#app';
19
+ import type { ObjectPlugin, Plugin } from 'nuxt/app';
20
20
  declare const _default: Plugin & ObjectPlugin;
21
21
  export default _default;
@@ -14,6 +14,6 @@
14
14
  * did (a hydration mismatch). After the mount, hydration has already seen the server's text.
15
15
  * How a project translates messages during SSR: README, "Error Translation".
16
16
  */
17
- import type { ObjectPlugin, Plugin } from '#app';
17
+ import type { ObjectPlugin, Plugin } from 'nuxt/app';
18
18
  declare const _default: Plugin & ObjectPlugin;
19
19
  export default _default;
@@ -66,7 +66,7 @@
66
66
  *
67
67
  * Default on; opt out with `ltExtensions.formLabelAssociation.enabled: false`.
68
68
  */
69
- import type { ObjectPlugin, Plugin } from '#app';
69
+ import type { ObjectPlugin, Plugin } from 'nuxt/app';
70
70
  /**
71
71
  * Re-point every dangling field label at the control in its own field.
72
72
  *
@@ -12,6 +12,6 @@
12
12
  * `warnMissingLtApiUrl()` is one-shot, so the warning still appears exactly once
13
13
  * per process — and `buildLtApiUrl()` shares the same key, so it never repeats.
14
14
  */
15
- import type { ObjectPlugin, Plugin } from '#app';
15
+ import type { ObjectPlugin, Plugin } from 'nuxt/app';
16
16
  declare const _default: ObjectPlugin & Plugin;
17
17
  export default _default;
@@ -51,7 +51,7 @@
51
51
  * browsers do not raise the on-screen keyboard for it. Preserving the entry avoids all of
52
52
  * that, because the field is never anything other than a normal, editable field.
53
53
  */
54
- import type { ObjectPlugin, Plugin } from '#app';
54
+ import type { ObjectPlugin, Plugin } from 'nuxt/app';
55
55
  type EditableField = HTMLInputElement | HTMLTextAreaElement;
56
56
  /**
57
57
  * Collect fields the user edited before hydration.
@@ -13,6 +13,11 @@ export interface LtUser {
13
13
  /**
14
14
  * Stored as `string | undefined`, never `null` — see {@link LtUserInput}, which is what
15
15
  * `setUser` accepts. Reading code therefore has one empty case to handle, not two.
16
+ *
17
+ * An inline image (a `data:` URL, as Better-Auth's Microsoft provider stores the profile photo)
18
+ * is never stored, because it would push the `lt-auth-state` cookie past the browser's limit, so
19
+ * it reads as `undefined` here. Read the photo from the session answer
20
+ * (`GET <basePath>/get-session`) where an avatar needs it; an `http(s)` URL or a path is kept.
16
21
  */
17
22
  image?: string;
18
23
  name?: string;
@@ -48,6 +53,8 @@ export interface LtUser {
48
53
  * `setUser` normalises `null` to `undefined` on the way in, so the stored user and every
49
54
  * reader keep the single empty case. Widening `LtUser.image` itself would have done the
50
55
  * opposite: pushed a second empty value onto everyone who only READS it.
56
+ *
57
+ * An `image` that is a `data:` URL is stored as `undefined` as well (see {@link LtUser.image}).
51
58
  */
52
59
  export type LtUserInput = Omit<LtUser, 'image'> & {
53
60
  image?: null | string;
@@ -151,6 +158,54 @@ type NoStrayCredential<T, Own extends string> = Omit<{
151
158
  newPassword?: never;
152
159
  password?: never;
153
160
  }, Own> & T;
161
+ /**
162
+ * Parameters of a sign-in through a social provider (`POST <basePath>/sign-in/social`), as
163
+ * Better-Auth takes them. `provider` is the key the API configured under
164
+ * `betterAuth.socialProviders` (`'google'`, `'github'`, `'microsoft'`, …); `/iam/features` lists
165
+ * the enabled ones as `socialProviders`.
166
+ *
167
+ * Without `idToken` the answer is the provider's authorization URL and the browser goes there.
168
+ * It comes back to `callbackURL` signed in, or to `errorCallbackURL` with `?error=`. Both must be
169
+ * absolute URLs of an origin the API trusts (`trustedOrigins`): Better-Auth resolves a relative
170
+ * value against the API.
171
+ */
172
+ export interface LtSocialSignInParams {
173
+ /** Data Better-Auth carries through the OAuth flow and hands to its hooks. */
174
+ additionalData?: Record<string, unknown>;
175
+ /**
176
+ * Extra query parameters for the provider's authorization URL, for this request only.
177
+ * `{ prompt: 'none' }` asks for a silent sign-in: the provider answers without showing
178
+ * anything, with the session if the user has one there and with an error otherwise
179
+ * (`errorCallbackURL`). `{ prompt: 'select_account' }` lets the user pick another account.
180
+ */
181
+ additionalParams?: Record<string, string>;
182
+ /** Where the browser lands after a successful sign-in. */
183
+ callbackURL?: string;
184
+ /** Answer with the authorization URL without navigating to it. */
185
+ disableRedirect?: boolean;
186
+ /** Where the browser lands when the provider or Better-Auth refuses; the reason is in `?error=`. */
187
+ errorCallbackURL?: string;
188
+ /**
189
+ * Sign in with an ID token the provider already issued for this application, without a
190
+ * redirect: an app inside a host that knows the user (Microsoft Teams, a native shell).
191
+ */
192
+ idToken?: {
193
+ accessToken?: string;
194
+ nonce?: string;
195
+ refreshToken?: string;
196
+ token: string;
197
+ };
198
+ /** The account to suggest to the provider (an e-mail address), which skips its account picker. */
199
+ loginHint?: string;
200
+ /** Where the browser lands after a sign-in that created the account. */
201
+ newUserCallbackURL?: string;
202
+ /** The provider's key on the API. */
203
+ provider: string;
204
+ /** Ask for a new account where the provider is configured with `disableImplicitSignUp`. */
205
+ requestSignUp?: boolean;
206
+ /** Scopes to request on top of the ones the API configured. */
207
+ scopes?: string[];
208
+ }
154
209
  export interface UseLtAuthReturn {
155
210
  authMode: ComputedRef<LtAuthMode>;
156
211
  isAuthenticated: ComputedRef<boolean>;
@@ -280,7 +335,8 @@ export interface UseLtAuthReturn {
280
335
  *
281
336
  * Accepts {@link LtUserInput}, so `getSession().data.user` can be handed over unchanged —
282
337
  * Better Auth writes "no picture" as `image: null`, which this normalises to `undefined`
283
- * before storing. Readers of {@link LtUser} keep a single empty case.
338
+ * before storing. Readers of {@link LtUser} keep a single empty case. An inline `data:` image
339
+ * is not stored either (see {@link LtUser.image}).
284
340
  */
285
341
  setUser: (userData: LtUserInput | null, mode?: LtAuthMode) => void;
286
342
  signIn: {
@@ -290,6 +346,12 @@ export interface UseLtAuthReturn {
290
346
  rememberMe?: boolean;
291
347
  }>(params: NoStrayCredential<T, 'password'>, options?: unknown) => Promise<unknown>;
292
348
  passkey?: (options?: unknown) => Promise<unknown>;
349
+ /**
350
+ * Sign-in through a social provider the API configured (see {@link LtSocialSignInParams}).
351
+ * A redirect answer leaves the page; an ID-token answer signs the user in at once, on the
352
+ * cookie session, with the JWT fetched from `/iam/token`.
353
+ */
354
+ social: (params: LtSocialSignInParams, options?: unknown) => Promise<unknown>;
293
355
  };
294
356
  signOut: (options?: unknown) => Promise<unknown>;
295
357
  signUp: {
@@ -1,4 +1,4 @@
1
- export type { LtAuthClientConfig, LtAuthMode, LtAuthResponse, LtAuthState, LtPasskeyAuthResult, LtPasskeyRegisterResult, LtUser, LtUserInput, UseLtAuthReturn } from './auth.js';
1
+ export type { LtAuthClientConfig, LtAuthMode, LtAuthResponse, LtAuthState, LtPasskeyAuthResult, LtPasskeyRegisterResult, LtSocialSignInParams, LtUser, LtUserInput, UseLtAuthReturn, } from './auth.js';
2
2
  export type { LtFileInfo, LtUploadItem, LtUploadOptions, LtUploadProgress, LtUploadStatus, UseLtFileReturn, UseLtTusUploadReturn } from './upload.js';
3
3
  export type { LtAiModuleOptions, LtAuthCookieNamesOptions, LtAuthModuleOptions, LtErrorTranslationModuleOptions, LtExtensionsModuleOptions, LtExtensionsPublicRuntimeConfig, LtFormLabelAssociationOptions, LtI18nModuleOptions, LtPreHydrationInputOptions, LtSecurityTxtOptions, LtSystemSetupModuleOptions, LtTusModuleOptions, } from './module.js';
4
4
  export type { LtErrorTranslationResponse, LtParsedError, UseLtErrorTranslationReturn } from './error.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lenne.tech/nuxt-extensions",
3
- "version": "4.0.2",
3
+ "version": "4.0.3",
4
4
  "description": "Reusable Nuxt 4 composables, components, and Better-Auth integration for lenne.tech projects",
5
5
  "repository": {
6
6
  "type": "git",
@@ -111,27 +111,27 @@
111
111
  },
112
112
  "devDependencies": {
113
113
  "@better-auth/passkey": "1.7.19",
114
- "@nuxt/module-builder": "1.0.3",
114
+ "@nuxt/module-builder": "1.0.4",
115
115
  "@nuxt/schema": "4.6.4",
116
- "@nuxt/ui": "4.12.0",
117
- "@playwright/test": "1.65.0",
116
+ "@nuxt/ui": "4.12.2",
117
+ "@playwright/test": "1.65.1",
118
118
  "@types/node": "26.6.6",
119
- "@vitest/coverage-v8": "5.1.0",
119
+ "@vitest/coverage-v8": "5.1.1",
120
120
  "@vue/server-renderer": "3.5.45",
121
121
  "better-auth": "1.7.19",
122
122
  "cross-spawn": "7.0.6",
123
123
  "fake-indexeddb": "6.2.8",
124
124
  "happy-dom": "21.0.4",
125
125
  "nuxt": "4.6.4",
126
- "oxfmt": "0.78.0",
127
- "oxlint": "1.93.0",
128
- "oxlint-tsgolint": "7.0.2006",
126
+ "oxfmt": "0.79.0",
127
+ "oxlint": "1.94.0",
128
+ "oxlint-tsgolint": "7.0.2007",
129
129
  "reka-ui": "2.11.0",
130
130
  "semver": "7.8.6",
131
131
  "tailwindcss": "4.3.5",
132
132
  "tus-js-client": "4.3.1",
133
133
  "typescript": "5.9.3",
134
- "vitest": "5.1.0",
134
+ "vitest": "5.1.1",
135
135
  "vue-tsc": "3.3.14"
136
136
  },
137
137
  "keywords": [