better-auth-nuxt 0.0.10-beta.22 → 0.0.10-beta.23

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/dist/module.d.mts CHANGED
@@ -4,14 +4,30 @@ export { BetterAuthModuleOptions, defineClientAuth, defineServerAuth } from '../
4
4
  import { BetterAuthOptions } from 'better-auth';
5
5
  export { Auth, AuthMeta, AuthMode, AuthRouteRules, AuthSession, AuthUser, InferSession, InferUser, RequireSessionOptions, ServerAuthContext, UserMatch } from '../dist/runtime/types.js';
6
6
 
7
+ interface ClientPluginImport {
8
+ /** Import path to the plugin file (e.g., 'my-module/runtime/client-plugin') */
9
+ from: string;
10
+ /** Named export to import (e.g., 'myPlugin'). If not specified, uses default export. */
11
+ name?: string;
12
+ }
13
+ interface ClientExtendConfig {
14
+ /** Plugin imports to add to the client config */
15
+ plugins?: ClientPluginImport[];
16
+ }
7
17
  declare module '@nuxt/schema' {
8
18
  interface NuxtHooks {
9
19
  /**
10
- * Extend better-auth config with additional plugins or options.
11
- * Called after user's auth.config.ts is loaded.
12
- * @param config - Partial config to merge into the auth options
20
+ * Extend better-auth server config with additional plugins or options.
21
+ * Called during schema generation for NuxtHub database.
22
+ * @param config - Partial config to merge into the server auth options
13
23
  */
14
24
  'better-auth:config:extend': (config: Partial<BetterAuthOptions>) => void | Promise<void>;
25
+ /**
26
+ * Extend better-auth client config with additional plugins.
27
+ * Called during module setup, affects runtime client.
28
+ * @param config - Plugin imports to merge into the client auth options
29
+ */
30
+ 'better-auth:client:extend': (config: ClientExtendConfig) => void | Promise<void>;
15
31
  }
16
32
  }
17
33
 
package/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "better-auth-nuxt",
3
- "version": "0.0.10-beta.22",
3
+ "version": "0.0.10-beta.23",
4
4
  "configKey": "auth",
5
5
  "compatibility": {
6
6
  "nuxt": ">=3.0.0"
package/dist/module.mjs CHANGED
@@ -11,7 +11,7 @@ import { generateDrizzleSchema as generateDrizzleSchema$1 } from '@better-auth/c
11
11
  import { getAuthTables } from 'better-auth/db';
12
12
  export { defineClientAuth, defineServerAuth } from '../dist/runtime/config.js';
13
13
 
14
- const version = "0.0.10-beta.22";
14
+ const version = "0.0.10-beta.23";
15
15
 
16
16
  function dialectToProvider(dialect) {
17
17
  return dialect === "postgresql" ? "pg" : dialect;
@@ -509,6 +509,52 @@ declare module '#nuxt-better-auth' {
509
509
  }
510
510
  `
511
511
  });
512
+ const extendedClientConfig = {};
513
+ await nuxt.callHook("better-auth:client:extend", extendedClientConfig);
514
+ const hasClientExtensions = extendedClientConfig.plugins && extendedClientConfig.plugins.length > 0;
515
+ if (hasClientExtensions) {
516
+ const pluginImports = extendedClientConfig.plugins.map((plugin, index) => {
517
+ const importName = plugin.name || `plugin${index}`;
518
+ return plugin.name ? `import { ${plugin.name} as ${importName} } from '${plugin.from}'` : `import ${importName} from '${plugin.from}'`;
519
+ }).join("\n");
520
+ const pluginNames = extendedClientConfig.plugins.map((plugin, index) => {
521
+ return plugin.name || `plugin${index}`;
522
+ }).join(", ");
523
+ const clientExtensionsCode = `
524
+ import createUserAuthClient from '${clientConfigPath}'
525
+ import { createAuthClient } from 'better-auth/vue'
526
+ ${pluginImports}
527
+
528
+ // Extended plugins from better-auth:client:extend hook
529
+ const extendedPlugins = [${pluginNames}]
530
+
531
+ export default function createAppAuthClient(baseURL) {
532
+ const ctx = { siteUrl: baseURL }
533
+ const userConfig = typeof createUserAuthClient === 'function'
534
+ ? (() => {
535
+ // Call the user's defineClientAuth result to get the client
536
+ const result = createUserAuthClient(baseURL)
537
+ // If it returns a client directly, we need to recreate with merged plugins
538
+ return result
539
+ })()
540
+ : createUserAuthClient
541
+
542
+ // Merge extended plugins with user plugins
543
+ return createAuthClient({
544
+ baseURL,
545
+ ...userConfig,
546
+ plugins: [...extendedPlugins, ...(userConfig.plugins || [])],
547
+ })
548
+ }
549
+ `;
550
+ const clientExtTemplate = addTemplate({
551
+ filename: "better-auth/client-extended.mjs",
552
+ getContents: () => clientExtensionsCode,
553
+ write: true
554
+ });
555
+ nuxt.options.alias["#auth/client"] = clientExtTemplate.dst;
556
+ consola.info("Client config extended via better-auth:client:extend hook");
557
+ }
512
558
  nuxt.hook("builder:watch", async (_event, relativePath) => {
513
559
  if (relativePath.includes("auth.config")) {
514
560
  await updateTemplates({ filter: (t) => t.filename.includes("nuxt-better-auth") });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "better-auth-nuxt",
3
3
  "type": "module",
4
- "version": "0.0.10-beta.22",
4
+ "version": "0.0.10-beta.23",
5
5
  "description": "Nuxt module for Better Auth integration with NuxtHub, route protection, session management, and role-based access",
6
6
  "author": "onmax",
7
7
  "license": "MIT",