@nuxtjs/better-auth 0.3.13 → 0.3.14
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
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.14";
|
|
17
17
|
|
|
18
18
|
const CONFIG_EXTENSIONS = [".ts", ".js", ".mts", ".cts", ".mjs", ".cjs"];
|
|
19
19
|
const CONFIG_EXTENSION_RE = /\.[cm]?[jt]s$/;
|
|
@@ -966,7 +966,8 @@ function getCloudflareContext(event) {
|
|
|
966
966
|
|
|
967
967
|
function resolveHyperdrive(event) {
|
|
968
968
|
const cloudflareEnv = getCloudflareContext(event)?.env
|
|
969
|
-
|
|
969
|
+
const runtimeEnv = event?.req?.runtime?.cloudflare?.env
|
|
970
|
+
return cloudflareEnv?.POSTGRES || runtimeEnv?.POSTGRES || process.env.POSTGRES || globalThis.__env__?.POSTGRES || globalThis.POSTGRES
|
|
970
971
|
}
|
|
971
972
|
|
|
972
973
|
function scheduleCleanup(event, cleanup) {
|
|
@@ -1008,6 +1009,11 @@ function registerClientCleanup(event, client) {
|
|
|
1008
1009
|
response.once('close', cleanup)
|
|
1009
1010
|
}
|
|
1010
1011
|
|
|
1012
|
+
// Hyperdrive clients belong to one request; any other database is shared by the whole process.
|
|
1013
|
+
export function isRequestScopedDatabase(event) {
|
|
1014
|
+
return Boolean(resolveHyperdrive(event)?.connectionString)
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1011
1017
|
export function createDatabase(event) {
|
|
1012
1018
|
const hyperdrive = resolveHyperdrive(event)
|
|
1013
1019
|
if (!hyperdrive?.connectionString)
|
|
@@ -1045,10 +1051,12 @@ import * as schema from './schema.${input.hubDialect}.mjs'
|
|
|
1045
1051
|
import { drizzleAdapter } from 'better-auth/adapters/drizzle'
|
|
1046
1052
|
const rawDialect = '${input.hubDialect}'
|
|
1047
1053
|
const dialect = rawDialect === 'postgresql' ? 'pg' : rawDialect
|
|
1054
|
+
export function isRequestScopedDatabase() { return false }
|
|
1048
1055
|
export function createDatabase() { return drizzleAdapter(db, { provider: dialect, schema, usePlural: ${input.usePlural}, camelCase: ${input.camelCase} }) }
|
|
1049
1056
|
export { db }`;
|
|
1050
1057
|
}
|
|
1051
|
-
return `export function
|
|
1058
|
+
return `export function isRequestScopedDatabase() { return false }
|
|
1059
|
+
export function createDatabase() { return undefined }
|
|
1052
1060
|
export const db = undefined`;
|
|
1053
1061
|
}
|
|
1054
1062
|
function buildSchemaExportCode(hasHubDb, hubDialect, modelNames = {}) {
|
|
@@ -1330,6 +1338,7 @@ type AvailableRouterMethod<_ReqT extends NitroFetchRequest> = 'get' | 'head' | '
|
|
|
1330
1338
|
declare module '#auth/database' {
|
|
1331
1339
|
import type { BetterAuthOptions } from 'better-auth'
|
|
1332
1340
|
export function createDatabase(event?: import('${h3TypesPath}').H3Event): BetterAuthOptions['database']
|
|
1341
|
+
export function isRequestScopedDatabase(event?: import('${h3TypesPath}').H3Event): boolean
|
|
1333
1342
|
export const db: ${hasHubDb ? `typeof import('@nuxthub/db')['db']` : "undefined"}
|
|
1334
1343
|
}
|
|
1335
1344
|
`
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { betterAuth, env } from "better-auth";
|
|
2
|
-
import { createDatabase, db } from "#auth/database";
|
|
2
|
+
import { createDatabase, db, isRequestScopedDatabase } from "#auth/database";
|
|
3
3
|
import createServerAuth from "#auth/server";
|
|
4
4
|
import { getConfiguredAuthSecret, getDerivedAuthSecret, hasExplicitAuthSecret, prepareAuthSecret } from "../internal/auth-secret.js";
|
|
5
5
|
import { getRequestHost, getRequestProtocol, useRuntimeConfig } from "../internal/nitro-compat.js";
|
|
@@ -248,6 +248,15 @@ export function serverAuth(event) {
|
|
|
248
248
|
const requestContext = event ? getRequestAuthContext(event) : void 0;
|
|
249
249
|
if (requestContext?.[requestAuthKey])
|
|
250
250
|
return requestContext[requestAuthKey];
|
|
251
|
+
const requestScopedDatabase = isRequestScopedDatabase(event);
|
|
252
|
+
if (!requestScopedDatabase) {
|
|
253
|
+
const cached = _authCache.get(cacheKey);
|
|
254
|
+
if (cached) {
|
|
255
|
+
if (requestContext)
|
|
256
|
+
requestContext[requestAuthKey] = cached;
|
|
257
|
+
return cached;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
251
260
|
userConfig ??= createServerAuth({ runtimeConfig, db, requestOrigin });
|
|
252
261
|
const usesDerivedSecret = derived.available && userConfig.secrets === void 0 && !hasExplicitAuthSecret(runtimeConfig);
|
|
253
262
|
const derivedSecretMissing = usesDerivedSecret && !derived.secret;
|
|
@@ -276,15 +285,7 @@ export function serverAuth(event) {
|
|
|
276
285
|
console.warn('[nuxt-better-auth] rateLimit.storage: "secondary-storage" requires secondaryStorage. Falling back to process-local memory. Set rateLimit.storage to "database" or provide rateLimit.customStorage for shared limits.');
|
|
277
286
|
}
|
|
278
287
|
const rateLimit = useMemoryRateLimit ? { ...userConfig.rateLimit, storage: "memory" } : userConfig.rateLimit;
|
|
279
|
-
const cacheable = !
|
|
280
|
-
if (cacheable) {
|
|
281
|
-
const cached = _authCache.get(cacheKey);
|
|
282
|
-
if (cached) {
|
|
283
|
-
if (requestContext)
|
|
284
|
-
requestContext[requestAuthKey] = cached;
|
|
285
|
-
return cached;
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
+
const cacheable = !requestScopedDatabase && !derivedSecretMissing;
|
|
288
289
|
const authOptions = {
|
|
289
290
|
...userConfig,
|
|
290
291
|
...userConfig.plugins ? { plugins: [...userConfig.plugins] } : {},
|
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.14",
|
|
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",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"peerDependencies": {
|
|
62
62
|
"@nuxt/test-utils": "^4.1.0",
|
|
63
63
|
"@nuxthub/core": ">=0.10.5",
|
|
64
|
-
"auth": "1.7.
|
|
64
|
+
"auth": "1.7.13",
|
|
65
65
|
"better-auth": ">=1.7.3 <2"
|
|
66
66
|
},
|
|
67
67
|
"peerDependenciesMeta": {
|
|
@@ -106,8 +106,8 @@
|
|
|
106
106
|
"@types/better-sqlite3": "^9.6.0",
|
|
107
107
|
"@typescript/typescript6": "6.0.2",
|
|
108
108
|
"@vue/test-utils": "^2.4.6",
|
|
109
|
-
"auth": "1.7.
|
|
110
|
-
"better-auth": "1.7.
|
|
109
|
+
"auth": "1.7.13",
|
|
110
|
+
"better-auth": "1.7.13",
|
|
111
111
|
"better-call": "1.4.4",
|
|
112
112
|
"better-sqlite3": "^13.0.0",
|
|
113
113
|
"drizzle-kit": "^0.31.10",
|