@lenne.tech/nuxt-extensions 1.1.1 → 1.2.0

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/README.md CHANGED
@@ -127,6 +127,49 @@ async function handlePasskeyLogin() {
127
127
  </template>
128
128
  ```
129
129
 
130
+ ### Custom Better Auth Plugins
131
+
132
+ You can extend the auth client with additional [Better Auth plugins](https://www.better-auth.com/docs/plugins):
133
+
134
+ **Option 1: Plugin Registration (recommended)**
135
+
136
+ Create a Nuxt plugin to register plugins before the auth client is initialized:
137
+
138
+ ```typescript
139
+ // plugins/auth-plugins.client.ts
140
+ import { registerLtAuthPlugins } from '@lenne.tech/nuxt-extensions';
141
+ import { organizationClient, magicLinkClient } from 'better-auth/client/plugins';
142
+
143
+ export default defineNuxtPlugin(() => {
144
+ registerLtAuthPlugins([
145
+ organizationClient(),
146
+ magicLinkClient(),
147
+ ]);
148
+ });
149
+ ```
150
+
151
+ **Option 2: Direct Factory Usage**
152
+
153
+ For full control, create the auth client directly with your plugins:
154
+
155
+ ```typescript
156
+ import { createLtAuthClient } from '@lenne.tech/nuxt-extensions';
157
+ import { organizationClient } from 'better-auth/client/plugins';
158
+
159
+ const authClient = createLtAuthClient({
160
+ plugins: [organizationClient()],
161
+ });
162
+
163
+ // Use authClient.organization.* methods
164
+ ```
165
+
166
+ **Available Better Auth Plugins:**
167
+ - `organizationClient` - Organization/team management
168
+ - `magicLinkClient` - Passwordless email login
169
+ - `oneTapClient` - Google One Tap login
170
+ - `anonymousClient` - Anonymous/guest sessions
171
+ - See [Better Auth Plugins](https://www.better-auth.com/docs/plugins) for full list
172
+
130
173
  ### TUS File Upload
131
174
 
132
175
  ```vue
@@ -276,6 +319,7 @@ The package works **with or without** `@nuxtjs/i18n`:
276
319
  | `ltArrayBufferToBase64Url()` | ArrayBuffer to base64url conversion |
277
320
  | `ltBase64UrlToUint8Array()` | Base64url to Uint8Array conversion |
278
321
  | `createLtAuthClient()` | Auth client factory for custom configuration |
322
+ | `registerLtAuthPlugins()` | Register custom Better Auth plugins |
279
323
 
280
324
  ## Related Projects
281
325
 
@@ -8,6 +8,37 @@
8
8
  * plain text password transmission over the network.
9
9
  */
10
10
  import type { LtAuthClientConfig } from "../types/index.js";
11
+ /**
12
+ * Register additional Better Auth plugins before auth client initialization.
13
+ *
14
+ * Call this in a Nuxt plugin (client-side) or in app.vue setup before
15
+ * the auth client is used.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * // plugins/auth-plugins.client.ts
20
+ * import { registerLtAuthPlugins } from '@lenne.tech/nuxt-extensions';
21
+ * import { organizationClient, magicLinkClient } from 'better-auth/client/plugins';
22
+ *
23
+ * export default defineNuxtPlugin(() => {
24
+ * registerLtAuthPlugins([
25
+ * organizationClient(),
26
+ * magicLinkClient(),
27
+ * ]);
28
+ * });
29
+ * ```
30
+ */
31
+ export declare function registerLtAuthPlugins(plugins: unknown[]): void;
32
+ /**
33
+ * Get the current plugin registry.
34
+ * Used internally by createLtAuthClient.
35
+ */
36
+ export declare function getLtAuthPluginRegistry(): unknown[];
37
+ /**
38
+ * Clear the plugin registry.
39
+ * Useful for testing or resetting state.
40
+ */
41
+ export declare function clearLtAuthPluginRegistry(): void;
11
42
  /**
12
43
  * Creates a configured Better-Auth client with password hashing
13
44
  *
@@ -4,6 +4,16 @@ import { createAuthClient } from "better-auth/vue";
4
4
  import { navigateTo } from "#imports";
5
5
  import { ltSha256 } from "../utils/crypto.js";
6
6
  import { createLtAuthFetch, isLtDevMode } from "./auth-state.js";
7
+ let _ltAuthPluginRegistry = [];
8
+ export function registerLtAuthPlugins(plugins) {
9
+ _ltAuthPluginRegistry = [..._ltAuthPluginRegistry, ...plugins];
10
+ }
11
+ export function getLtAuthPluginRegistry() {
12
+ return _ltAuthPluginRegistry;
13
+ }
14
+ export function clearLtAuthPluginRegistry() {
15
+ _ltAuthPluginRegistry = [];
16
+ }
7
17
  export function createLtAuthClient(config = {}) {
8
18
  const isDev = isLtDevMode();
9
19
  const defaultBaseURL = isDev ? "" : import.meta.env?.VITE_API_URL || process.env.API_URL || "http://localhost:3000";
@@ -14,7 +24,8 @@ export function createLtAuthClient(config = {}) {
14
24
  twoFactorRedirectPath = "/auth/2fa",
15
25
  enableAdmin = true,
16
26
  enableTwoFactor = true,
17
- enablePasskey = true
27
+ enablePasskey = true,
28
+ plugins: externalPlugins = []
18
29
  } = config;
19
30
  const plugins = [];
20
31
  if (enableAdmin) {
@@ -32,6 +43,8 @@ export function createLtAuthClient(config = {}) {
32
43
  if (enablePasskey) {
33
44
  plugins.push(passkeyClient());
34
45
  }
46
+ plugins.push(...externalPlugins);
47
+ plugins.push(..._ltAuthPluginRegistry);
35
48
  const authFetch = createLtAuthFetch(basePath.replace("/api", ""));
36
49
  const baseClient = createAuthClient({
37
50
  basePath,
@@ -1,2 +1,2 @@
1
1
  export { attemptLtJwtSwitch, createLtAuthFetch, getLtApiBase, getLtAuthMode, getLtJwtToken, isLtAuthenticated, ltAuthFetch, setLtAuthMode, setLtJwtToken, } from "./auth-state.js";
2
- export { createLtAuthClient, type LtAuthClient } from "./auth-client.js";
2
+ export { clearLtAuthPluginRegistry, createLtAuthClient, getLtAuthPluginRegistry, registerLtAuthPlugins, type LtAuthClient, } from "./auth-client.js";
@@ -9,4 +9,9 @@ export {
9
9
  setLtAuthMode,
10
10
  setLtJwtToken
11
11
  } from "./auth-state.js";
12
- export { createLtAuthClient } from "./auth-client.js";
12
+ export {
13
+ clearLtAuthPluginRegistry,
14
+ createLtAuthClient,
15
+ getLtAuthPluginRegistry,
16
+ registerLtAuthPlugins
17
+ } from "./auth-client.js";
@@ -45,6 +45,8 @@ export interface LtAuthClientConfig {
45
45
  enableTwoFactor?: boolean;
46
46
  /** 2FA redirect path (default: '/auth/2fa') */
47
47
  twoFactorRedirectPath?: string;
48
+ /** Additional Better Auth client plugins (e.g., organizationClient, magicLinkClient) */
49
+ plugins?: unknown[];
48
50
  }
49
51
  /**
50
52
  * Normalized response type for Better-Auth operations
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lenne.tech/nuxt-extensions",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "description": "Reusable Nuxt 4 composables, components, and Better-Auth integration for lenne.tech projects",
5
5
  "repository": {
6
6
  "type": "git",