@lenne.tech/nuxt-extensions 1.2.7 → 1.2.8

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.
@@ -1,13 +1,7 @@
1
- import { useNuxtApp, useRuntimeConfig, useCookie, useState, ref, computed, watch } from "#imports";
1
+ import { useNuxtApp, useCookie, useState, ref, computed, watch } from "#imports";
2
2
  import { ltArrayBufferToBase64Url, ltBase64UrlToUint8Array } from "../../utils/crypto.js";
3
- import { createLtAuthClient } from "../../lib/auth-client.js";
4
- let _authClient = null;
5
- function getAuthClient() {
6
- if (!_authClient) {
7
- _authClient = createLtAuthClient();
8
- }
9
- return _authClient;
10
- }
3
+ import { getLtApiBase } from "../../lib/auth-state.js";
4
+ import { useLtAuthClient } from "../use-lt-auth-client.js";
11
5
  function useTranslation() {
12
6
  const nuxtApp = useNuxtApp();
13
7
  const i18n = nuxtApp.$i18n;
@@ -19,7 +13,7 @@ function useTranslation() {
19
13
  };
20
14
  }
21
15
  export function useLtAuth() {
22
- const authClient = getAuthClient();
16
+ const authClient = useLtAuthClient();
23
17
  const t = useTranslation();
24
18
  const authState = useCookie("lt-auth-state", {
25
19
  maxAge: 60 * 60 * 24 * 7,
@@ -62,14 +56,6 @@ export function useLtAuth() {
62
56
  () => ({})
63
57
  );
64
58
  const featuresFetched = useState("lt-auth-features-fetched", () => false);
65
- function getApiBase() {
66
- const isDev = import.meta.dev;
67
- const runtimeConfig = useRuntimeConfig();
68
- const config = runtimeConfig.public.ltExtensions?.auth;
69
- const baseURL = config?.baseURL || "http://localhost:3000";
70
- const basePath = config?.basePath || "/iam";
71
- return isDev ? `/api${basePath}` : `${baseURL}${basePath}`;
72
- }
73
59
  function setUser(userData, mode = "cookie") {
74
60
  const newState = { user: userData, authMode: mode };
75
61
  authState.value = newState;
@@ -103,7 +89,7 @@ export function useLtAuth() {
103
89
  }
104
90
  async function switchToJwtMode() {
105
91
  try {
106
- const apiBase = getApiBase();
92
+ const apiBase = getLtApiBase();
107
93
  const response = await fetch(`${apiBase}/token`, {
108
94
  method: "GET",
109
95
  credentials: "include"
@@ -191,7 +177,7 @@ export function useLtAuth() {
191
177
  }
192
178
  async function fetchFeatures() {
193
179
  try {
194
- const apiBase = getApiBase();
180
+ const apiBase = getLtApiBase();
195
181
  const result = await $fetch(
196
182
  `${apiBase}/features`
197
183
  );
@@ -269,7 +255,7 @@ export function useLtAuth() {
269
255
  async function authenticateWithPasskey() {
270
256
  isLoading.value = true;
271
257
  try {
272
- const apiBase = getApiBase();
258
+ const apiBase = getLtApiBase();
273
259
  const optionsResponse = await fetchWithAuth(
274
260
  `${apiBase}/passkey/generate-authenticate-options`,
275
261
  {
@@ -363,7 +349,7 @@ export function useLtAuth() {
363
349
  async function registerPasskey(name) {
364
350
  isLoading.value = true;
365
351
  try {
366
- const apiBase = getApiBase();
352
+ const apiBase = getLtApiBase();
367
353
  const optionsResponse = await fetchWithAuth(`${apiBase}/passkey/generate-register-options`, {
368
354
  method: "GET"
369
355
  });
@@ -3,30 +3,15 @@ import {
3
3
  getOrCreateLtAuthClient,
4
4
  resetLtAuthClientSingleton
5
5
  } from "../lib/auth-client.js";
6
+ import { isLtDevMode } from "../lib/auth-state.js";
6
7
  export function resetLtAuthClient() {
7
8
  resetLtAuthClientSingleton();
8
9
  }
9
- function isDevMode() {
10
- if (import.meta.server) {
11
- return process.env.NODE_ENV !== "production";
12
- }
13
- if (typeof window !== "undefined") {
14
- const buildId = window.__NUXT__?.config?.app?.buildId;
15
- if (buildId === "dev") {
16
- return true;
17
- }
18
- const hostname = window.location?.hostname;
19
- if (hostname === "localhost" || hostname === "127.0.0.1") {
20
- return true;
21
- }
22
- }
23
- return false;
24
- }
25
10
  export function useLtAuthClient() {
26
11
  try {
27
12
  const nuxtApp = useNuxtApp();
28
13
  const config = nuxtApp.$config?.public?.ltExtensions?.auth || {};
29
- const isDev = isDevMode();
14
+ const isDev = isLtDevMode();
30
15
  let basePath = config.basePath || "/iam";
31
16
  if (isDev && basePath && !basePath.startsWith("/api")) {
32
17
  basePath = `/api${basePath}`;
@@ -40,7 +40,7 @@ export declare function setLtAuthMode(mode: LtAuthMode): void;
40
40
  /**
41
41
  * Get the API base URL from runtime config
42
42
  *
43
- * @param basePath - The auth API base path (default: '/iam')
43
+ * @param basePath - The auth API base path. If not provided, reads from runtime config (default: '/iam')
44
44
  */
45
45
  export declare function getLtApiBase(basePath?: string): string;
46
46
  /**
@@ -68,7 +68,11 @@ export function setLtAuthMode(mode) {
68
68
  } catch {
69
69
  }
70
70
  }
71
- export function getLtApiBase(basePath = "/iam") {
71
+ export function getLtApiBase(basePath) {
72
+ if (!basePath && typeof window !== "undefined") {
73
+ basePath = window.__NUXT__?.config?.public?.ltExtensions?.auth?.basePath;
74
+ }
75
+ basePath = basePath || "/iam";
72
76
  const isDev = isLtDevMode();
73
77
  if (isDev) {
74
78
  return `/api${basePath}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lenne.tech/nuxt-extensions",
3
- "version": "1.2.7",
3
+ "version": "1.2.8",
4
4
  "description": "Reusable Nuxt 4 composables, components, and Better-Auth integration for lenne.tech projects",
5
5
  "repository": {
6
6
  "type": "git",
@@ -53,7 +53,7 @@
53
53
  "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxt prepare playground",
54
54
  "build": "nuxt-module-build build",
55
55
  "lint": "oxlint src/",
56
- "lint:fix": "oxlint --fix src/",
56
+ "lint:fix": "oxlint --fix --fix-suggestions src/",
57
57
  "format": "oxfmt --write src/",
58
58
  "format:check": "oxfmt --check src/",
59
59
  "test": "vitest run",
@@ -119,4 +119,4 @@
119
119
  "file-upload",
120
120
  "lenne-tech"
121
121
  ]
122
- }
122
+ }