@nuxtjs/better-auth 0.3.5 → 0.3.6
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 +39 -23
- package/dist/runtime/app/composables/useAuthClient.js +4 -1
- package/dist/runtime/internal/auth-base-url.d.ts +2 -0
- package/dist/runtime/internal/auth-base-url.js +5 -0
- package/dist/runtime/server/api/_better-auth/_schema.d.ts +7 -0
- package/dist/runtime/server/utils/auth.js +2 -1
- package/dist/runtime/server/virtual-modules.d.ts +0 -4
- package/package.json +1 -1
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -13,7 +13,7 @@ import { isCI, isTest } from 'std-env';
|
|
|
13
13
|
import { isInternalAssetPath } from '../dist/runtime/internal/auth-route-rules.js';
|
|
14
14
|
export { defineClientAuth, defineServerAuth } from '../dist/runtime/config.js';
|
|
15
15
|
|
|
16
|
-
const version = "0.3.
|
|
16
|
+
const version = "0.3.6";
|
|
17
17
|
|
|
18
18
|
const CONFIG_EXTENSIONS = [".ts", ".js", ".mts", ".cts", ".mjs", ".cjs"];
|
|
19
19
|
const CONFIG_EXTENSION_RE = /\.[cm]?[jt]s$/;
|
|
@@ -332,8 +332,7 @@ function registerPrepareTypesHook(input) {
|
|
|
332
332
|
nodeTsConfig.compilerOptions.paths ||= {};
|
|
333
333
|
const projectReferenceTypePaths = [
|
|
334
334
|
join(nuxt.options.buildDir, "types/nitro-imports.d.ts"),
|
|
335
|
-
join(nuxt.options.buildDir, "types/auth-database.d.ts")
|
|
336
|
-
join(nuxt.options.buildDir, "types/auth-schema.d.ts")
|
|
335
|
+
join(nuxt.options.buildDir, "types/auth-database.d.ts")
|
|
337
336
|
];
|
|
338
337
|
if (hasHubDb)
|
|
339
338
|
projectReferenceTypePaths.push(join(nuxt.options.buildDir, "hub/db.d.ts"));
|
|
@@ -342,7 +341,8 @@ function registerPrepareTypesHook(input) {
|
|
|
342
341
|
"#auth/server": nuxt.options.alias["#auth/server"],
|
|
343
342
|
"#auth/client": nuxt.options.alias["#auth/client"],
|
|
344
343
|
"#auth/database": nuxt.options.alias["#auth/database"],
|
|
345
|
-
|
|
344
|
+
// An exact .mjs path bypasses declaration lookup in TypeScript paths.
|
|
345
|
+
"#auth/schema": join(nuxt.options.buildDir, "better-auth/schema"),
|
|
346
346
|
"#auth/route-rules": nuxt.options.alias["#auth/route-rules"]
|
|
347
347
|
};
|
|
348
348
|
for (const [key, value] of Object.entries(exactNodeAliases)) {
|
|
@@ -934,6 +934,36 @@ export const verification = getGeneratedTable('verification')
|
|
|
934
934
|
export const schema = { ...generatedSchema, user, session, account, verification }
|
|
935
935
|
`;
|
|
936
936
|
}
|
|
937
|
+
function buildSchemaExportTypes(hasHubDb, hubDialect) {
|
|
938
|
+
if (!hasHubDb) {
|
|
939
|
+
return `export declare const user: undefined
|
|
940
|
+
export declare const session: undefined
|
|
941
|
+
export declare const account: undefined
|
|
942
|
+
export declare const verification: undefined
|
|
943
|
+
export declare const schema: undefined
|
|
944
|
+
`;
|
|
945
|
+
}
|
|
946
|
+
return `export * from './schema.${hubDialect}.js'
|
|
947
|
+
|
|
948
|
+
type GeneratedSchema = typeof import('./schema.${hubDialect}.js')
|
|
949
|
+
type GeneratedTable<Name extends string> = Name extends keyof GeneratedSchema
|
|
950
|
+
? GeneratedSchema[Name]
|
|
951
|
+
: \`\${Name}s\` extends keyof GeneratedSchema
|
|
952
|
+
? GeneratedSchema[\`\${Name}s\`]
|
|
953
|
+
: undefined
|
|
954
|
+
|
|
955
|
+
export declare const user: GeneratedTable<'user'>
|
|
956
|
+
export declare const session: GeneratedTable<'session'>
|
|
957
|
+
export declare const account: GeneratedTable<'account'>
|
|
958
|
+
export declare const verification: GeneratedTable<'verification'>
|
|
959
|
+
export declare const schema: GeneratedSchema & {
|
|
960
|
+
user: typeof user
|
|
961
|
+
session: typeof session
|
|
962
|
+
account: typeof account
|
|
963
|
+
verification: typeof verification
|
|
964
|
+
}
|
|
965
|
+
`;
|
|
966
|
+
}
|
|
937
967
|
function buildAuthRouteRulesCode(authRouteRules) {
|
|
938
968
|
return `export const authRouteRules = ${JSON.stringify(authRouteRules, null, 2)}
|
|
939
969
|
`;
|
|
@@ -1165,24 +1195,6 @@ declare module '#auth/database' {
|
|
|
1165
1195
|
export function createDatabase(event?: import('${h3TypesPath}').H3Event): BetterAuthOptions['database']
|
|
1166
1196
|
export const db: ${hasHubDb ? `typeof import('@nuxthub/db')['db']` : "undefined"}
|
|
1167
1197
|
}
|
|
1168
|
-
`
|
|
1169
|
-
}, { nitro: true });
|
|
1170
|
-
addTypeTemplate({
|
|
1171
|
-
filename: "types/auth-schema.d.ts",
|
|
1172
|
-
getContents: () => `
|
|
1173
|
-
declare module '#auth/schema' {
|
|
1174
|
-
export const user: any
|
|
1175
|
-
export const session: any
|
|
1176
|
-
export const account: any
|
|
1177
|
-
export const verification: any
|
|
1178
|
-
export const schema: {
|
|
1179
|
-
user: any
|
|
1180
|
-
session: any
|
|
1181
|
-
account: any
|
|
1182
|
-
verification: any
|
|
1183
|
-
[key: string]: any
|
|
1184
|
-
} | undefined
|
|
1185
|
-
}
|
|
1186
1198
|
`
|
|
1187
1199
|
}, { nitro: true });
|
|
1188
1200
|
addTypeTemplate({
|
|
@@ -1190,7 +1202,6 @@ declare module '#auth/schema' {
|
|
|
1190
1202
|
getContents: () => `
|
|
1191
1203
|
/// <reference path="./nitro-imports.d.ts" />
|
|
1192
1204
|
/// <reference path="./auth-database.d.ts" />
|
|
1193
|
-
/// <reference path="./auth-schema.d.ts" />
|
|
1194
1205
|
${hasHubDb ? '/// <reference path="../hub/db.d.ts" />' : ""}
|
|
1195
1206
|
|
|
1196
1207
|
export {}
|
|
@@ -1679,6 +1690,11 @@ const module$1 = defineNuxtModule({
|
|
|
1679
1690
|
write: true
|
|
1680
1691
|
});
|
|
1681
1692
|
nuxt.options.alias["#auth/schema"] = schemaTemplate.dst;
|
|
1693
|
+
addTemplate({
|
|
1694
|
+
filename: "better-auth/schema.d.ts",
|
|
1695
|
+
getContents: () => buildSchemaExportTypes(setup.database.hasHubDb, setup.database.buildContext?.hubDialect ?? "sqlite"),
|
|
1696
|
+
write: true
|
|
1697
|
+
});
|
|
1682
1698
|
if (setup.schemaGeneration)
|
|
1683
1699
|
await ensureSchemaBootstrap(schemaTemplate.dst, setup.database.buildContext?.hubDialect ?? "sqlite");
|
|
1684
1700
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import createAppAuthClient from "#auth/client";
|
|
2
2
|
import { useRequestURL, useRuntimeConfig } from "#imports";
|
|
3
|
+
import { resolveAuthBaseURL } from "../../internal/auth-base-url.js";
|
|
3
4
|
import { createVueSafeAuthProxy } from "../internal/vue-safe-auth-proxy.js";
|
|
4
5
|
let _client = null;
|
|
5
6
|
let _clientFacade = null;
|
|
@@ -27,7 +28,9 @@ export function useRawAuthClient() {
|
|
|
27
28
|
const requestURL = useRequestURL();
|
|
28
29
|
const configuredSiteUrl = runtimeConfig.public.siteUrl;
|
|
29
30
|
const siteUrl = typeof configuredSiteUrl === "string" && configuredSiteUrl ? configuredSiteUrl : requestURL.origin;
|
|
30
|
-
|
|
31
|
+
const clientOnly = runtimeConfig.public.auth?.clientOnly;
|
|
32
|
+
const appBaseURL = runtimeConfig.app?.baseURL;
|
|
33
|
+
return getClient(clientOnly ? siteUrl : resolveAuthBaseURL(siteUrl, appBaseURL));
|
|
31
34
|
}
|
|
32
35
|
export function useAuthClient() {
|
|
33
36
|
const rawClient = useRawAuthClient();
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { Account, Session, User } from 'better-auth/types';
|
|
2
|
+
import type { AnyColumn, Table } from 'drizzle-orm';
|
|
1
3
|
import { z } from 'zod';
|
|
2
4
|
export declare const paginationQuerySchema: z.ZodObject<{
|
|
3
5
|
page: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
@@ -6,3 +8,8 @@ export declare const paginationQuerySchema: z.ZodObject<{
|
|
|
6
8
|
}, z.core.$strip>;
|
|
7
9
|
export type PaginationQuery = z.infer<typeof paginationQuerySchema>;
|
|
8
10
|
export declare function sanitizeSearchPattern(search: string): string;
|
|
11
|
+
export type DevtoolsSchema = {
|
|
12
|
+
user?: Table & Record<keyof User, AnyColumn>;
|
|
13
|
+
session?: Table & Record<keyof Session, AnyColumn>;
|
|
14
|
+
account?: Table & Record<keyof Account, AnyColumn>;
|
|
15
|
+
} | undefined;
|
|
@@ -3,6 +3,7 @@ import { withoutProtocol } from "ufo";
|
|
|
3
3
|
import { createDatabase, db } from "#auth/database";
|
|
4
4
|
import createServerAuth from "#auth/server";
|
|
5
5
|
import { getRequestHost, getRequestProtocol, useRuntimeConfig } from "../internal/nitro-compat.js";
|
|
6
|
+
import { resolveAuthBaseURL } from "../../internal/auth-base-url.js";
|
|
6
7
|
import { resolveCustomSecondaryStorageRequirement } from "./custom-secondary-storage.js";
|
|
7
8
|
const _authCache = /* @__PURE__ */ new Map();
|
|
8
9
|
const requestAuthKey = Symbol.for("nuxt-better-auth.requestAuth");
|
|
@@ -254,7 +255,7 @@ export function serverAuth(event) {
|
|
|
254
255
|
...rateLimit ? { rateLimit } : {},
|
|
255
256
|
...database ? { database } : {},
|
|
256
257
|
secret: betterAuthSecret,
|
|
257
|
-
baseURL: siteUrl,
|
|
258
|
+
baseURL: resolveAuthBaseURL(siteUrl, runtimeConfig.app?.baseURL),
|
|
258
259
|
trustedOrigins
|
|
259
260
|
};
|
|
260
261
|
const auth = betterAuth(authOptions);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxtjs/better-auth",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.6",
|
|
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",
|