better-auth-nuxt 0.0.10-beta.21 → 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.21",
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
@@ -1,7 +1,7 @@
1
1
  import { randomBytes } from 'node:crypto';
2
2
  import { existsSync, writeFileSync, readFileSync } from 'node:fs';
3
3
  import { mkdir, writeFile } from 'node:fs/promises';
4
- import { defineNuxtModule, createResolver, hasNuxtModule, addTemplate, addTypeTemplate, updateTemplates, addServerImportsDir, addServerImports, addServerScanDir, addServerHandler, addImportsDir, addPlugin, addComponentsDir, installModule, extendPages } from '@nuxt/kit';
4
+ import { defineNuxtModule, createResolver, hasNuxtModule, addTemplate, addTypeTemplate, updateTemplates, addServerImportsDir, addServerImports, addServerScanDir, addServerHandler, addImportsDir, addPlugin, addComponentsDir } from '@nuxt/kit';
5
5
  import { consola as consola$1 } from 'consola';
6
6
  import { defu } from 'defu';
7
7
  import { join, dirname } from 'pathe';
@@ -11,22 +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.21";
15
-
16
- function setupDevTools(nuxt) {
17
- nuxt.hook("devtools:customTabs", (tabs) => {
18
- tabs.push({
19
- category: "server",
20
- name: "better-auth",
21
- title: "Auth",
22
- icon: "simple-icons:betterauth",
23
- view: {
24
- type: "iframe",
25
- src: "/__better-auth-devtools"
26
- }
27
- });
28
- });
29
- }
14
+ const version = "0.0.10-beta.23";
30
15
 
31
16
  function dialectToProvider(dialect) {
32
17
  return dialect === "postgresql" ? "pg" : dialect;
@@ -524,6 +509,52 @@ declare module '#nuxt-better-auth' {
524
509
  }
525
510
  `
526
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
+ }
527
558
  nuxt.hook("builder:watch", async (_event, relativePath) => {
528
559
  if (relativePath.includes("auth.config")) {
529
560
  await updateTemplates({ filter: (t) => t.filename.includes("nuxt-better-auth") });
@@ -552,9 +583,6 @@ declare module '#nuxt-better-auth' {
552
583
  }
553
584
  const isProduction = process.env.NODE_ENV === "production" || !nuxt.options.dev;
554
585
  if (!isProduction && !clientOnly) {
555
- if (!hasNuxtModule("@nuxt/ui"))
556
- await installModule("@nuxt/ui");
557
- setupDevTools(nuxt);
558
586
  addServerHandler({ route: "/api/_better-auth/config", method: "GET", handler: resolver.resolve("./runtime/server/api/_better-auth/config.get") });
559
587
  if (hasHubDb) {
560
588
  addServerHandler({ route: "/api/_better-auth/sessions", method: "GET", handler: resolver.resolve("./runtime/server/api/_better-auth/sessions.get") });
@@ -562,9 +590,6 @@ declare module '#nuxt-better-auth' {
562
590
  addServerHandler({ route: "/api/_better-auth/users", method: "GET", handler: resolver.resolve("./runtime/server/api/_better-auth/users.get") });
563
591
  addServerHandler({ route: "/api/_better-auth/accounts", method: "GET", handler: resolver.resolve("./runtime/server/api/_better-auth/accounts.get") });
564
592
  }
565
- extendPages((pages) => {
566
- pages.push({ name: "better-auth-devtools", path: "/__better-auth-devtools", file: resolver.resolve("./runtime/app/pages/__better-auth-devtools.vue") });
567
- });
568
593
  }
569
594
  nuxt.hook("pages:extend", (pages) => {
570
595
  const routeRules = nuxt.options.routeRules || {};
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.21",
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",