@lenne.tech/nuxt-extensions 1.2.2 → 1.2.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.
@@ -110,7 +110,6 @@ export function useLtAuth() {
110
110
  if (authState.value) {
111
111
  authState.value = { ...authState.value, authMode: "jwt" };
112
112
  }
113
- console.debug("[LtAuth] Switched to JWT mode");
114
113
  return true;
115
114
  }
116
115
  }
@@ -123,26 +122,30 @@ export function useLtAuth() {
123
122
  if (!isJwtMode.value || !jwtToken.value) return false;
124
123
  return switchToJwtMode();
125
124
  }
125
+ const PATHS_REQUIRING_COOKIES = ["/passkey/", "/two-factor/", "/2fa/"];
126
+ function urlRequiresCookies(url) {
127
+ return PATHS_REQUIRING_COOKIES.some((path) => url.includes(path));
128
+ }
126
129
  async function fetchWithAuth(url, options = {}) {
127
130
  const headers = new Headers(options.headers);
128
131
  if (isJwtMode.value && jwtToken.value) {
129
132
  headers.set("Authorization", `Bearer ${jwtToken.value}`);
130
133
  }
134
+ const needsCookies = !isJwtMode.value || urlRequiresCookies(url);
131
135
  const response = await fetch(url, {
132
136
  ...options,
133
137
  headers,
134
- // Only include credentials in cookie mode
135
- credentials: isJwtMode.value ? "omit" : "include"
138
+ credentials: needsCookies ? "include" : "omit"
136
139
  });
137
140
  if (response.status === 401 && !isJwtMode.value && isAuthenticated.value) {
138
- console.debug("[LtAuth] Cookie auth failed, attempting JWT fallback...");
139
141
  const switched = await switchToJwtMode();
140
142
  if (switched) {
141
143
  headers.set("Authorization", `Bearer ${jwtToken.value}`);
144
+ const retryNeedsCookies = urlRequiresCookies(url);
142
145
  return fetch(url, {
143
146
  ...options,
144
147
  headers,
145
- credentials: "omit"
148
+ credentials: retryNeedsCookies ? "include" : "omit"
146
149
  });
147
150
  }
148
151
  }
@@ -177,8 +180,7 @@ export function useLtAuth() {
177
180
  return true;
178
181
  }
179
182
  return false;
180
- } catch (error) {
181
- console.debug("Session validation failed:", error);
183
+ } catch {
182
184
  return !!authState.value?.user;
183
185
  }
184
186
  }
@@ -197,7 +199,6 @@ export function useLtAuth() {
197
199
  if (userData) {
198
200
  setUser(userData, "jwt");
199
201
  }
200
- console.debug("[LtAuth] JWT token received from login response");
201
202
  } else if (userData) {
202
203
  setUser(userData, "cookie");
203
204
  switchToJwtMode().catch(() => {
@@ -224,7 +225,6 @@ export function useLtAuth() {
224
225
  if (userData) {
225
226
  setUser(userData, "jwt");
226
227
  }
227
- console.debug("[LtAuth] JWT token received from signup response");
228
228
  } else if (userData) {
229
229
  setUser(userData, "cookie");
230
230
  switchToJwtMode().catch(() => {
@@ -310,7 +310,6 @@ export function useLtAuth() {
310
310
  if (authState.value) {
311
311
  authState.value = { ...authState.value, authMode: "jwt" };
312
312
  }
313
- console.debug("[LtAuth] Passkey: Stored session token as JWT");
314
313
  }
315
314
  return { success: true, user: result.user, session: result.session };
316
315
  } catch (err) {
@@ -1,9 +1,13 @@
1
1
  import { useNuxtApp } from "#imports";
2
- import { createLtAuthClient } from "../lib/auth-client.js";
2
+ import {
3
+ createLtAuthClient,
4
+ setResetAuthClientCallback
5
+ } from "../lib/auth-client.js";
3
6
  let authClientInstance = null;
4
7
  export function resetLtAuthClient() {
5
8
  authClientInstance = null;
6
9
  }
10
+ setResetAuthClientCallback(resetLtAuthClient);
7
11
  function isDevMode() {
8
12
  if (import.meta.server) {
9
13
  return process.env.NODE_ENV !== "production";
@@ -8,16 +8,24 @@
8
8
  * plain text password transmission over the network.
9
9
  */
10
10
  import type { LtAuthClientConfig } from "../types/index.js";
11
+ /**
12
+ * Set the callback to reset the auth client.
13
+ * Called internally by use-lt-auth-client.ts
14
+ */
15
+ export declare function setResetAuthClientCallback(callback: () => void): void;
11
16
  /**
12
17
  * Register additional Better Auth plugins before auth client initialization.
13
18
  *
14
19
  * Call this in a Nuxt plugin (client-side) or in app.vue setup before
15
20
  * the auth client is used.
16
21
  *
22
+ * If the auth client was already created, it will be automatically reset
23
+ * so the next call recreates it with the new plugins.
24
+ *
17
25
  * @example
18
26
  * ```typescript
19
27
  * // plugins/auth-plugins.client.ts
20
- * import { registerLtAuthPlugins } from '@lenne.tech/nuxt-extensions';
28
+ * import { registerLtAuthPlugins } from '@lenne.tech/nuxt-extensions/lib';
21
29
  * import { organizationClient, magicLinkClient } from 'better-auth/client/plugins';
22
30
  *
23
31
  * export default defineNuxtPlugin(() => {
@@ -5,8 +5,15 @@ import { navigateTo } from "#imports";
5
5
  import { ltSha256 } from "../utils/crypto.js";
6
6
  import { createLtAuthFetch, isLtDevMode } from "./auth-state.js";
7
7
  let _ltAuthPluginRegistry = [];
8
+ let _resetAuthClientCallback = null;
9
+ export function setResetAuthClientCallback(callback) {
10
+ _resetAuthClientCallback = callback;
11
+ }
8
12
  export function registerLtAuthPlugins(plugins) {
9
13
  _ltAuthPluginRegistry = [..._ltAuthPluginRegistry, ...plugins];
14
+ if (_resetAuthClientCallback) {
15
+ _resetAuthClientCallback();
16
+ }
10
17
  }
11
18
  export function getLtAuthPluginRegistry() {
12
19
  return _ltAuthPluginRegistry;
@@ -1,2 +1,2 @@
1
1
  export { attemptLtJwtSwitch, createLtAuthFetch, getLtApiBase, getLtAuthMode, getLtJwtToken, isLtAuthenticated, ltAuthFetch, setLtAuthMode, setLtJwtToken, } from "./auth-state.js";
2
- export { clearLtAuthPluginRegistry, createLtAuthClient, getLtAuthPluginRegistry, registerLtAuthPlugins, type LtAuthClient, } from "./auth-client.js";
2
+ export { clearLtAuthPluginRegistry, createLtAuthClient, getLtAuthPluginRegistry, registerLtAuthPlugins, setResetAuthClientCallback, type LtAuthClient, } from "./auth-client.js";
@@ -13,5 +13,6 @@ export {
13
13
  clearLtAuthPluginRegistry,
14
14
  createLtAuthClient,
15
15
  getLtAuthPluginRegistry,
16
- registerLtAuthPlugins
16
+ registerLtAuthPlugins,
17
+ setResetAuthClientCallback
17
18
  } from "./auth-client.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lenne.tech/nuxt-extensions",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "description": "Reusable Nuxt 4 composables, components, and Better-Auth integration for lenne.tech projects",
5
5
  "repository": {
6
6
  "type": "git",