@nuxtjs/better-auth 0.2.3 → 0.2.4
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 +1 -1
- package/dist/module.mjs +24 -9
- package/package.json +1 -1
package/dist/module.json
CHANGED
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,
|
|
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.
|
|
13
|
+
const version = "0.2.4";
|
|
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
|
-
|
|
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
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxtjs/better-auth",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.4",
|
|
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",
|