@onmax/nuxt-better-auth 0.0.2-alpha.22 → 0.0.2-alpha.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.json +1 -1
- package/dist/module.mjs +32 -10
- package/dist/runtime/server/utils/session.d.ts +10 -2
- 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.2-alpha.
|
|
13
|
+
const version = "0.0.2-alpha.23";
|
|
14
14
|
|
|
15
15
|
function resolveDatabaseProvider(input) {
|
|
16
16
|
const enabledProviders = Object.entries(input.providers).filter(([_id, provider]) => provider.isEnabled?.(input.context) ?? true);
|
|
@@ -235,6 +235,21 @@ async function loadUserAuthConfig(configPath, throwOnError = false) {
|
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
237
|
|
|
238
|
+
function isInsideNodeModules(path) {
|
|
239
|
+
return path.split(/[\\/]/).includes("node_modules");
|
|
240
|
+
}
|
|
241
|
+
function resolveHubSchemaPath(buildDir, rootDir, dialect, exists = existsSync) {
|
|
242
|
+
const rootTsPath = join(rootDir, ".nuxt", "better-auth", `schema.${dialect}.ts`);
|
|
243
|
+
if (isInsideNodeModules(buildDir) && exists(rootTsPath))
|
|
244
|
+
return rootTsPath;
|
|
245
|
+
const tsPath = join(buildDir, "better-auth", `schema.${dialect}.ts`);
|
|
246
|
+
if (exists(tsPath))
|
|
247
|
+
return tsPath;
|
|
248
|
+
const mjsPath = join(buildDir, "better-auth", `schema.${dialect}.mjs`);
|
|
249
|
+
if (exists(mjsPath))
|
|
250
|
+
return mjsPath;
|
|
251
|
+
return null;
|
|
252
|
+
}
|
|
238
253
|
async function loadAuthOptions(context) {
|
|
239
254
|
const isProduction = !context.nuxt.options.dev;
|
|
240
255
|
const configFile = `${context.serverConfigPath}.ts`;
|
|
@@ -270,19 +285,20 @@ async function setupBetterAuthSchema(nuxt, serverConfigPath, options, consola) {
|
|
|
270
285
|
await mkdir(schemaDir, { recursive: true });
|
|
271
286
|
await writeFile(schemaPathTs, schemaCode);
|
|
272
287
|
await writeFile(schemaPathMjs, schemaCode);
|
|
288
|
+
if (isInsideNodeModules(nuxt.options.buildDir)) {
|
|
289
|
+
const rootSchemaDir = join(nuxt.options.rootDir, ".nuxt", "better-auth");
|
|
290
|
+
const rootSchemaPathTs = join(rootSchemaDir, `schema.${dialect}.ts`);
|
|
291
|
+
await mkdir(rootSchemaDir, { recursive: true });
|
|
292
|
+
await writeFile(rootSchemaPathTs, schemaCode);
|
|
293
|
+
}
|
|
273
294
|
addTemplate({ filename: `better-auth/schema.${dialect}.ts`, getContents: () => schemaCode, write: true });
|
|
274
295
|
addTemplate({ filename: `better-auth/schema.${dialect}.mjs`, getContents: () => schemaCode, write: true });
|
|
275
296
|
consola.info(`Generated ${dialect} schema (.ts + .mjs)`);
|
|
276
297
|
const nuxtWithHubHooks = nuxt;
|
|
277
298
|
nuxtWithHubHooks.hook("hub:db:schema:extend", ({ paths, dialect: hookDialect }) => {
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
paths.unshift(tsPath);
|
|
282
|
-
return;
|
|
283
|
-
}
|
|
284
|
-
if (existsSync(mjsPath))
|
|
285
|
-
paths.unshift(mjsPath);
|
|
299
|
+
const schemaPath = resolveHubSchemaPath(nuxt.options.buildDir, nuxt.options.rootDir, hookDialect);
|
|
300
|
+
if (schemaPath)
|
|
301
|
+
paths.unshift(schemaPath);
|
|
286
302
|
});
|
|
287
303
|
} catch (error) {
|
|
288
304
|
const isProduction = !nuxt.options.dev;
|
|
@@ -491,8 +507,14 @@ function registerSharedTypeTemplates(input) {
|
|
|
491
507
|
addTypeTemplate({
|
|
492
508
|
filename: "types/nuxt-better-auth.d.ts",
|
|
493
509
|
getContents: () => `
|
|
510
|
+
import type { AuthSession, AuthUser } from '${input.runtimeTypesAugmentPath}'
|
|
511
|
+
import type { UserMatch } from '${input.runtimeTypesPath}'
|
|
494
512
|
export * from '${input.runtimeTypesAugmentPath}'
|
|
495
|
-
export type { AuthMeta, AuthMode, AuthRouteRules, UserMatch,
|
|
513
|
+
export type { AuthMeta, AuthMode, AuthRouteRules, UserMatch, Auth, InferUser, InferSession } from '${input.runtimeTypesPath}'
|
|
514
|
+
export interface RequireSessionOptions {
|
|
515
|
+
user?: UserMatch<AuthUser>
|
|
516
|
+
rule?: (ctx: { user: AuthUser, session: AuthSession }) => boolean | Promise<boolean>
|
|
517
|
+
}
|
|
496
518
|
`
|
|
497
519
|
});
|
|
498
520
|
addTypeTemplate({
|
|
@@ -1,9 +1,17 @@
|
|
|
1
|
+
import type { AuthSession, AuthUser } from '#nuxt-better-auth';
|
|
1
2
|
import type { H3Event } from 'h3';
|
|
2
|
-
import type {
|
|
3
|
+
import type { UserMatch } from '../../types.js';
|
|
3
4
|
interface FullSession {
|
|
4
5
|
user: AuthUser;
|
|
5
6
|
session: AuthSession;
|
|
6
7
|
}
|
|
8
|
+
interface RequireUserSessionOptions {
|
|
9
|
+
user?: UserMatch<AuthUser>;
|
|
10
|
+
rule?: (ctx: {
|
|
11
|
+
user: AuthUser;
|
|
12
|
+
session: AuthSession;
|
|
13
|
+
}) => boolean | Promise<boolean>;
|
|
14
|
+
}
|
|
7
15
|
export declare function getUserSession(event: H3Event): Promise<FullSession | null>;
|
|
8
|
-
export declare function requireUserSession(event: H3Event, options?:
|
|
16
|
+
export declare function requireUserSession(event: H3Event, options?: RequireUserSessionOptions): Promise<FullSession>;
|
|
9
17
|
export {};
|
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.2-alpha.
|
|
4
|
+
"version": "0.0.2-alpha.23",
|
|
5
5
|
"packageManager": "pnpm@10.15.1",
|
|
6
6
|
"description": "Nuxt module for Better Auth integration with NuxtHub, route protection, session management, and role-based access",
|
|
7
7
|
"author": "onmax",
|