@onmax/nuxt-better-auth 0.0.3 → 0.0.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 +28 -10
- package/package.json +1 -1
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -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.0.
|
|
13
|
+
const version = "0.0.4";
|
|
14
14
|
|
|
15
15
|
const CONFIG_EXTENSIONS = [".ts", ".js"];
|
|
16
16
|
const CONFIG_EXTENSION_RE = /\.(?:ts|js)$/;
|
|
@@ -293,7 +293,15 @@ async function generateDrizzleSchema(authOptions, dialect, schemaOptions) {
|
|
|
293
293
|
}
|
|
294
294
|
return result.code;
|
|
295
295
|
}
|
|
296
|
-
|
|
296
|
+
function loadLocalEnv(rootDir) {
|
|
297
|
+
if (!rootDir)
|
|
298
|
+
return;
|
|
299
|
+
const envPath = join(rootDir, ".env.local");
|
|
300
|
+
if (!existsSync(envPath))
|
|
301
|
+
return;
|
|
302
|
+
process.loadEnvFile(envPath);
|
|
303
|
+
}
|
|
304
|
+
async function loadUserAuthConfig(configPath, throwOnError = false, alias, runtimeConfig = {}, rootDir) {
|
|
297
305
|
const { createJiti } = await import('jiti');
|
|
298
306
|
const { defineServerAuth: runtimeDefineServerAuth } = await import('../dist/runtime/config.js');
|
|
299
307
|
const jiti = createJiti(import.meta.url, { interopDefault: true, moduleCache: false, alias });
|
|
@@ -307,6 +315,7 @@ async function loadUserAuthConfig(configPath, throwOnError = false, alias, runti
|
|
|
307
315
|
}
|
|
308
316
|
schemaGlobals.__nuxtBetterAuthDefineServerAuth._count++;
|
|
309
317
|
try {
|
|
318
|
+
loadLocalEnv(rootDir);
|
|
310
319
|
const mod = await jiti.import(configPath);
|
|
311
320
|
const configFn = mod.default;
|
|
312
321
|
if (typeof configFn === "function") {
|
|
@@ -386,7 +395,7 @@ async function loadAuthOptions(context) {
|
|
|
386
395
|
const alias = Object.fromEntries(
|
|
387
396
|
Object.entries(context.nuxt.options.alias).filter(([, value]) => typeof value === "string").map(([key, value]) => [key, value])
|
|
388
397
|
);
|
|
389
|
-
const userConfig = await loadUserAuthConfig(configFile, isProduction, alias, context.nuxt.options.runtimeConfig);
|
|
398
|
+
const userConfig = await loadUserAuthConfig(configFile, isProduction, alias, context.nuxt.options.runtimeConfig, context.nuxt.options.rootDir);
|
|
390
399
|
const extendedConfig = {};
|
|
391
400
|
await context.nuxt.callHook("better-auth:config:extend", extendedConfig);
|
|
392
401
|
const plugins = [...userConfig.plugins || [], ...extendedConfig.plugins || []];
|
|
@@ -728,11 +737,23 @@ export { db }`;
|
|
|
728
737
|
export const db = undefined`;
|
|
729
738
|
}
|
|
730
739
|
function buildSchemaExportCode(hasHubDb, hubDialect) {
|
|
731
|
-
if (!hasHubDb)
|
|
732
|
-
return
|
|
740
|
+
if (!hasHubDb) {
|
|
741
|
+
return `export const user = undefined
|
|
742
|
+
export const session = undefined
|
|
743
|
+
export const account = undefined
|
|
744
|
+
export const verification = undefined
|
|
745
|
+
export const schema = undefined
|
|
746
|
+
`;
|
|
747
|
+
}
|
|
733
748
|
return `export * from './schema.${hubDialect}.mjs'
|
|
734
|
-
import * as
|
|
735
|
-
|
|
749
|
+
import * as generatedSchema from './schema.${hubDialect}.mjs'
|
|
750
|
+
|
|
751
|
+
const getGeneratedTable = name => generatedSchema[name] ?? generatedSchema[\`\${name}s\`]
|
|
752
|
+
export const user = getGeneratedTable('user')
|
|
753
|
+
export const session = getGeneratedTable('session')
|
|
754
|
+
export const account = getGeneratedTable('account')
|
|
755
|
+
export const verification = getGeneratedTable('verification')
|
|
756
|
+
export const schema = { ...generatedSchema, user, session, account, verification }
|
|
736
757
|
`;
|
|
737
758
|
}
|
|
738
759
|
function buildAuthRouteRulesCode(authRouteRules) {
|
|
@@ -1174,7 +1195,6 @@ declare module 'nitropack' {
|
|
|
1174
1195
|
interface NitroRouteConfig {
|
|
1175
1196
|
auth?: import('${runtimeTypesPath}').AuthMeta
|
|
1176
1197
|
}
|
|
1177
|
-
interface InternalApi extends _GeneratedAuthInternalApi {}
|
|
1178
1198
|
}
|
|
1179
1199
|
declare module 'nitropack/types' {
|
|
1180
1200
|
interface NitroRouteRules {
|
|
@@ -1183,7 +1203,6 @@ declare module 'nitropack/types' {
|
|
|
1183
1203
|
interface NitroRouteConfig {
|
|
1184
1204
|
auth?: import('${runtimeTypesPath}').AuthMeta
|
|
1185
1205
|
}
|
|
1186
|
-
interface InternalApi extends _GeneratedAuthInternalApi {}
|
|
1187
1206
|
}
|
|
1188
1207
|
declare module 'nitro/types' {
|
|
1189
1208
|
interface NitroRouteRules {
|
|
@@ -1192,7 +1211,6 @@ declare module 'nitro/types' {
|
|
|
1192
1211
|
interface NitroRouteConfig {
|
|
1193
1212
|
auth?: import('${runtimeTypesPath}').AuthMeta
|
|
1194
1213
|
}
|
|
1195
|
-
interface InternalApi extends _GeneratedAuthInternalApi {}
|
|
1196
1214
|
}
|
|
1197
1215
|
export {}
|
|
1198
1216
|
`
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onmax/nuxt-better-auth",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.4",
|
|
5
5
|
"packageManager": "pnpm@11.1.0",
|
|
6
6
|
"description": "Nuxt module for Better Auth integration with NuxtHub, route protection, session management, and role-based access",
|
|
7
7
|
"author": "onmax",
|