@nuxtjs/better-auth 0.2.3 → 0.2.5

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.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxtjs/better-auth",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "configKey": "auth",
5
5
  "compatibility": {
6
6
  "nuxt": ">=4.0.0"
package/dist/module.mjs CHANGED
@@ -2,7 +2,7 @@ import { existsSync, statSync, writeFileSync, readFileSync } from 'node:fs';
2
2
  import { mkdir, writeFile } from 'node:fs/promises';
3
3
  import { getLayerDirectories, updateTemplates, addServerImportsDir, addServerImports, addServerScanDir, addServerHandler, addImportsDir, addPlugin, addComponentsDir, extendPages, addTemplate, hasNuxtModule, addTypeTemplate, defineNuxtModule, createResolver } from '@nuxt/kit';
4
4
  import { consola as consola$1 } from 'consola';
5
- import { isAbsolute, resolve, join, relative, dirname } from 'pathe';
5
+ import { isAbsolute, join, resolve, relative, dirname } from 'pathe';
6
6
  import { defu } from 'defu';
7
7
  import { toRouteMatcher, createRouter } from 'radix3';
8
8
  import { generateDrizzleSchema as generateDrizzleSchema$1 } from 'auth/api';
@@ -10,7 +10,7 @@ import { randomBytes } from 'node:crypto';
10
10
  import { isCI, isTest } from 'std-env';
11
11
  export { defineClientAuth, defineServerAuth } from '../dist/runtime/config.js';
12
12
 
13
- const version = "0.2.3";
13
+ const version = "0.2.5";
14
14
 
15
15
  const CONFIG_EXTENSIONS = [".ts", ".js"];
16
16
  const CONFIG_EXTENSION_RE$1 = /\.(?:ts|js)$/;
@@ -419,6 +419,17 @@ function resolveHubSchemaPath(buildDir, rootDir, dialect, exists = existsSync) {
419
419
  return mjsPath;
420
420
  return null;
421
421
  }
422
+ function registerNuxtHubSchemaHook(nuxt, finishSetup) {
423
+ const nuxtWithHubHooks = nuxt;
424
+ nuxtWithHubHooks.hook("hub:db:schema:extend", async ({ paths, dialect }) => {
425
+ const hasHubSchema = await finishSetup();
426
+ if (!hasHubSchema)
427
+ return;
428
+ const schemaPath = resolveHubSchemaPath(nuxt.options.buildDir, nuxt.options.rootDir, dialect);
429
+ if (schemaPath && !paths.includes(schemaPath))
430
+ paths.unshift(schemaPath);
431
+ });
432
+ }
422
433
  async function loadAuthOptions(context) {
423
434
  const isProduction = !context.nuxt.options.dev;
424
435
  const configFile = CONFIG_EXTENSION_RE.test(context.serverConfigPath) ? context.serverConfigPath : `${context.serverConfigPath}.ts`;
@@ -441,12 +452,6 @@ async function setupBetterAuthSchema(nuxt, serverConfigPath, options, consola, h
441
452
  return;
442
453
  }
443
454
  const context = { nuxt, serverConfigPath };
444
- const nuxtWithHubHooks = nuxt;
445
- nuxtWithHubHooks.hook("hub:db:schema:extend", ({ paths, dialect: hookDialect }) => {
446
- const schemaPath = resolveHubSchemaPath(nuxt.options.buildDir, nuxt.options.rootDir, hookDialect);
447
- if (schemaPath)
448
- paths.unshift(schemaPath);
449
- });
450
455
  try {
451
456
  const authConfig = await loadAuthOptions(context);
452
457
  if (!authConfig)
@@ -1411,7 +1416,7 @@ const module$1 = defineNuxtModule({
1411
1416
  await createDefaultAuthConfigFiles(nuxt);
1412
1417
  },
1413
1418
  setup(options, nuxt) {
1414
- nuxt.hook("modules:done", async () => {
1419
+ const finishSetup = async () => {
1415
1420
  const resolver = createResolver(import.meta.url);
1416
1421
  const nitroImports = resolveNitroCompatibilityImports(nuxt._version);
1417
1422
  nuxt.options.alias["#better-auth/nitro-compat"] = resolver.resolve(`./runtime/server/internal/${nitroImports.runtime}`);
@@ -1525,6 +1530,16 @@ const module$1 = defineNuxtModule({
1525
1530
  registerAuthMiddlewareHook(nuxt, resolver.resolve);
1526
1531
  await registerDevtools({ nuxt, clientOnly: setup.clientOnly, hasHubDb: setup.database.hasHubDb, resolve: resolver.resolve });
1527
1532
  registerRouteRulesMetaHook(nuxt);
1533
+ return Boolean(setup.schemaGeneration);
1534
+ };
1535
+ let setupPromise;
1536
+ const finishSetupOnce = () => {
1537
+ setupPromise ||= finishSetup();
1538
+ return setupPromise;
1539
+ };
1540
+ registerNuxtHubSchemaHook(nuxt, finishSetupOnce);
1541
+ nuxt.hook("modules:done", async () => {
1542
+ await finishSetupOnce();
1528
1543
  });
1529
1544
  }
1530
1545
  });
@@ -7,6 +7,7 @@ import { createVueSafeAuthFacade, isAuthProxyProbeKey } from "../internal/vue-sa
7
7
  import { wrapAuthMethod } from "../internal/wrap-auth-method.js";
8
8
  import { getAuthRuntimeFlags, useRawAuthClient } from "./useAuthClient.js";
9
9
  let _signOutPromise = null;
10
+ const _sessionSyncApps = /* @__PURE__ */ new WeakSet();
10
11
  function createServerOnlyActionNamespace(path) {
11
12
  return new Proxy({}, {
12
13
  get(_target, prop) {
@@ -96,7 +97,7 @@ export function useUserSession() {
96
97
  hydrationReconcileQueued.value = false;
97
98
  });
98
99
  }
99
- if (runtimeFlags.client && rawClient) {
100
+ if (runtimeFlags.client && rawClient && !_sessionSyncApps.has(nuxtApp)) {
100
101
  const clientSession = rawClient.useSession();
101
102
  const initialClientSession = clientSession.value;
102
103
  const shouldReconcileInitialHydration = nuxtApp.isHydrating && nuxtApp.payload.serverRendered && Boolean(session.value && user.value) && !initialClientSession?.data?.session && !initialClientSession?.data?.user && !initialClientSession?.isPending && !initialClientSession?.isRefetching;
@@ -123,6 +124,7 @@ export function useUserSession() {
123
124
  authReady.value = true;
124
125
  }
125
126
  );
127
+ _sessionSyncApps.add(nuxtApp);
126
128
  }
127
129
  function waitForSession() {
128
130
  return new Promise((resolve) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nuxtjs/better-auth",
3
3
  "type": "module",
4
- "version": "0.2.3",
4
+ "version": "0.2.5",
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",