@vite-hub/auth 0.6.0 → 0.7.0
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/README.md +28 -7
- package/dist/{abilities-D3XlrYDw.d.ts → abilities-CfvuGrBv.d.ts} +1 -1
- package/dist/abilities.d.ts +1 -1
- package/dist/{ability-error-D3-u8k1A.js → ability-error-OKoyOwPM.js} +1 -1
- package/dist/{access-pages-9aKr6z-k.js → access-pages-Bej95blM.js} +10 -3
- package/dist/agent.d.ts +2 -3
- package/dist/agent.js +25 -6
- package/dist/{auth-instance-BpI9Ps8A.js → auth-instance-5RSiFTDC.js} +151 -82
- package/dist/{cli-C5pAfY4x.d.ts → cli-DL7uCAvz.d.ts} +15 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +1 -1
- package/dist/client-request-BzMKtfCY.js +52 -0
- package/dist/{console-runtime-CaIXVtB_.js → console-runtime-Bg_PAl7e.js} +5 -3
- package/dist/{console-runtime-DAjLTLrN.d.ts → console-runtime-XcplYv4R.d.ts} +1 -1
- package/dist/console-runtime.d.ts +2 -2
- package/dist/console-runtime.js +1 -1
- package/dist/console.d.ts +1 -1
- package/dist/{database-options-B87hDU4j.js → database-options-DE9lMwu1.js} +1 -1
- package/dist/{database-schema-options-peXHNLkJ.js → database-schema-options-CCQsNhjc.js} +1 -1
- package/dist/database.d.ts +1 -1
- package/dist/database.js +4 -4
- package/dist/{definition-BypPLIbI.js → definition-DeEeqTLC.js} +18 -4
- package/dist/{error-diagnostics-CUPwukgE.js → error-diagnostics-DkzL9ltR.js} +13 -4
- package/dist/{events-BXU1_9mc.js → events-BUaoHFoC.js} +1 -1
- package/dist/forward.js +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +4 -3
- package/dist/internal/server.d.ts +3 -3
- package/dist/internal/server.js +5 -4
- package/dist/{mcp-token-CmQbXbTu.d.ts → mcp-token-DG1jmw4o.d.ts} +1 -0
- package/dist/{mcp-token-DzGivm7f.js → mcp-token-DgveSGEl.js} +28 -8
- package/dist/mcp.d.ts +1 -1
- package/dist/mcp.js +4 -2
- package/dist/{members-CwPIx10t.js → members-CRlYyxVk.js} +188 -152
- package/dist/nuxt.d.ts +1 -1
- package/dist/nuxt.js +27 -14
- package/dist/{own-access-Dt-I5-PT.d.ts → own-access-BvVUjaeL.d.ts} +1 -1
- package/dist/{page-tools-shared-CtoKaNQZ.js → page-tools-shared-dVJBPPTk.js} +8 -0
- package/dist/presets.js +1 -1
- package/dist/roles-BGi8CyBG.js +17 -0
- package/dist/runtime/client-request-plugin.d.ts +1 -0
- package/dist/runtime/client-request-plugin.js +18 -0
- package/dist/runtime/console.d.ts +1 -1
- package/dist/runtime/console.js +2 -2
- package/dist/runtime/empty-abilities.d.ts +1 -1
- package/dist/runtime/empty-definition.d.ts +1 -1
- package/dist/runtime/server.d.ts +2 -2
- package/dist/runtime/server.js +5 -3
- package/dist/runtime/vue-nuxt.js +27 -11
- package/dist/schema.js +1 -1
- package/dist/{server-Cun232hb.d.ts → server-1G_BbfBD.d.ts} +20 -7
- package/dist/{server-DL9MSuyj.d.ts → server-B8kTFrHP.d.ts} +3 -2
- package/dist/{server-_eUOlAJ8.js → server-iQNOXyfS.js} +50 -22
- package/dist/server.d.ts +5 -2
- package/dist/server.js +9 -3
- package/dist/{session-cookies-fR6Pv4kD.js → session-cookies-DN0svCKj.js} +2 -2
- package/dist/{set-cookie-DVfi-nJX.js → set-cookie-CMB3t4NF.js} +1 -1
- package/dist/{table-specs-CCSY4tiS.js → table-specs-C3-bLOSF.js} +1 -1
- package/dist/test.d.ts +1 -1
- package/dist/test.js +2 -2
- package/dist/{types-BP9_XUr9.d.ts → types-BmRGse4l.d.ts} +26 -5
- package/dist/{vite-Dem1i1rL.js → vite-GRzej8Cs.js} +59 -17
- package/dist/vite.d.ts +18 -3
- package/dist/vite.js +1 -1
- package/dist/vue.d.ts +2 -2
- package/dist/vue.js +1 -1
- package/package.json +9 -8
|
@@ -1,50 +1,32 @@
|
|
|
1
|
+
import { i as forwardedRequestOrigin, t as clientRequest } from "./client-request-BzMKtfCY.js";
|
|
1
2
|
import { t as isRecord } from "./object-CAK6UYR5.js";
|
|
2
3
|
import { i as resolveAuthMountPath } from "./application-path-zKi7NrvK.js";
|
|
3
|
-
import { a as readMembers, c as
|
|
4
|
-
import { o as authMemoryDatabaseError, r as authDatabaseName, t as assertAuthDatabaseIdStrategy } from "./database-options-
|
|
5
|
-
import { t as assertAuthDatabaseNames } from "./database-schema-options-
|
|
6
|
-
import { t as authErrorDiagnostics } from "./error-diagnostics-
|
|
7
|
-
import { a as
|
|
8
|
-
import {
|
|
9
|
-
import { i as parseAuthEventWindow, r as parseAuthEventList } from "./events-BXU1_9mc.js";
|
|
4
|
+
import { a as readMembers, c as createAdminClaimPlugin, f as createAdminsPlugin, h as createAccessPolicyPlugin, l as readAdminClaim, n as createMembersGate, o as withMemberScopes, p as readAdmins, t as assertMembersSessionStore } from "./members-CRlYyxVk.js";
|
|
5
|
+
import { o as authMemoryDatabaseError, r as authDatabaseName, t as assertAuthDatabaseIdStrategy } from "./database-options-DE9lMwu1.js";
|
|
6
|
+
import { t as assertAuthDatabaseNames } from "./database-schema-options-CCQsNhjc.js";
|
|
7
|
+
import { t as authErrorDiagnostics } from "./error-diagnostics-DkzL9ltR.js";
|
|
8
|
+
import { a as validateAuthComponents, c as validateAuthEvents, i as validateAuthAccessRouteRoles, l as applyAuthPreset, o as createDeleteAccount, r as validateAuthAccessPolicy, s as validateDeleteAccount, t as assertNoRuntimeOption } from "./definition-DeEeqTLC.js";
|
|
9
|
+
import { i as parseAuthEventWindow, r as parseAuthEventList } from "./events-BUaoHFoC.js";
|
|
10
10
|
import { t as forwardSignIns } from "./forward-sign-ins-BWXPPTRz.js";
|
|
11
|
+
import { n as authRequestEvent, t as authCloudflareEnv } from "./request-Dpq7GO8B.js";
|
|
11
12
|
import { n as resetAuth, t as getAuthRuntimeState } from "./runtime-state-C0Rd1W4m.js";
|
|
12
|
-
import {
|
|
13
|
-
import { r as throwAuthenticationProviderError, t as readSetCookies } from "./set-cookie-
|
|
14
|
-
import { n as viteHubPageToolsResetCookie, r as viteHubSessionMarkerCookie } from "./page-tools-shared-
|
|
13
|
+
import { o as normalizeAuthBasePath } from "./access-pages-Bej95blM.js";
|
|
14
|
+
import { r as throwAuthenticationProviderError, t as readSetCookies } from "./set-cookie-CMB3t4NF.js";
|
|
15
|
+
import { n as viteHubPageToolsResetCookie, r as viteHubSessionMarkerCookie } from "./page-tools-shared-dVJBPPTk.js";
|
|
15
16
|
import { resolvePublicUrl } from "@vite-hub/runtime";
|
|
16
17
|
import { getStandardContext } from "@vite-hub/runtime/internal/h3";
|
|
17
18
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
18
19
|
import { createAuthEndpoint, createAuthMiddleware, getOAuthState, getSessionFromCtx, isAPIError, sensitiveSessionMiddleware } from "better-auth/api";
|
|
19
20
|
import { getCookies } from "better-auth/cookies";
|
|
20
21
|
import { getAuthTables } from "better-auth/db";
|
|
21
|
-
import { APIError as APIError$1, betterAuth, createLogger, isRequestLike, resolveBaseURL } from "better-auth";
|
|
22
|
+
import { APIError as APIError$1, BetterAuthError, betterAuth, createLogger, getBaseURL, isDynamicBaseURLConfig, isRequestLike, resolveBaseURL, trimTrailingSlashes } from "better-auth";
|
|
22
23
|
import { memoryAdapter } from "better-auth/adapters/memory";
|
|
23
24
|
import definitionForApp, { getAuthApp } from "#vitehub/auth/definition";
|
|
25
|
+
import { configuredAppOrigin, configuredPublicOrigins } from "@vite-hub/runtime/internal/public-url";
|
|
24
26
|
import { getViteHubTestMode } from "@vite-hub/runtime/internal/test-mode";
|
|
25
27
|
import { isWebContainer } from "@vite-hub/web-container/env";
|
|
26
28
|
import { hkdfSync } from "node:crypto";
|
|
27
|
-
|
|
28
|
-
function firstHeaderValue(headers, name) {
|
|
29
|
-
return headers.get(name)?.split(",", 1)[0]?.trim() || void 0;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* The origin that the client used for `request`. A TLS-terminating proxy sends the client scheme in
|
|
33
|
-
* `X-Forwarded-Proto` and the client host in `X-Forwarded-Host`. Each proxy appends its value, so the first value wins.
|
|
34
|
-
* Without these headers, or with values that are not valid, the result is the origin of `request.url`.
|
|
35
|
-
*/
|
|
36
|
-
function forwardedRequestOrigin(request) {
|
|
37
|
-
const url = new URL(request.url);
|
|
38
|
-
const forwardedProtocol = firstHeaderValue(request.headers, "x-forwarded-proto")?.toLowerCase();
|
|
39
|
-
const protocol = forwardedProtocol === "http" || forwardedProtocol === "https" ? forwardedProtocol : url.protocol.slice(0, -1);
|
|
40
|
-
const host = firstHeaderValue(request.headers, "x-forwarded-host") ?? url.host;
|
|
41
|
-
if (/[\u0000-\u001F\s/\\?#@]/.test(host)) return url.origin;
|
|
42
|
-
try {
|
|
43
|
-
return new URL(`${protocol}://${host}`).origin;
|
|
44
|
-
} catch {
|
|
45
|
-
return url.origin;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
29
|
+
import { addRoute, createRouter, findRoute } from "better-auth-rou3";
|
|
48
30
|
// src/password.ts
|
|
49
31
|
const scryptOptions = {
|
|
50
32
|
N: 16384,
|
|
@@ -109,27 +91,44 @@ Object.freeze({ prefix: "sha256=" });
|
|
|
109
91
|
// src/secret.ts
|
|
110
92
|
/** The `deriveSecret()` purpose of the Better Auth secret. `vitehub secret derive vitehub:auth` prints it. */
|
|
111
93
|
const authSecretPurpose = "vitehub:auth";
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
"
|
|
115
|
-
|
|
116
|
-
|
|
94
|
+
const publicDefaultSecret = "better-auth-secret-12345678901234567890";
|
|
95
|
+
function parseVersionedSecrets(value) {
|
|
96
|
+
return value?.split(",").map((entry, index) => {
|
|
97
|
+
const separator = entry.indexOf(":");
|
|
98
|
+
const version = Number.parseInt(entry.slice(0, separator), 10);
|
|
99
|
+
const secret = entry.slice(separator + 1).trim();
|
|
100
|
+
if (separator === -1 || !Number.isInteger(version) || version < 0 || !secret) throw new BetterAuthError(`Invalid BETTER_AUTH_SECRETS entry at position ${index + 1}. Expected a non-negative version and a non-empty secret: "<version>:<secret>".`);
|
|
101
|
+
return {
|
|
102
|
+
version,
|
|
103
|
+
value: secret
|
|
104
|
+
};
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
function resolveAuthSecrets(options, bindings, development) {
|
|
108
|
+
const env = globalThis.process?.env;
|
|
109
|
+
const readEnvSecret = (name) => {
|
|
110
|
+
const binding = bindings?.[name];
|
|
111
|
+
return typeof binding === "string" && binding || env?.[name] || void 0;
|
|
112
|
+
};
|
|
113
|
+
const secrets = options.secrets ?? parseVersionedSecrets(readEnvSecret("BETTER_AUTH_SECRETS"));
|
|
114
|
+
const legacySecret = options.secret || readEnvSecret("BETTER_AUTH_SECRET") || readEnvSecret("AUTH_SECRET");
|
|
115
|
+
const keepDevelopmentDefault = development && (Object.hasOwn(options, "secret") || Object.hasOwn(options, "secrets"));
|
|
116
|
+
const secret = legacySecret ?? (secrets || keepDevelopmentDefault ? void 0 : deriveAuthSecret({
|
|
117
|
+
...env,
|
|
118
|
+
...bindings
|
|
119
|
+
}));
|
|
120
|
+
return {
|
|
121
|
+
secret,
|
|
122
|
+
secrets,
|
|
123
|
+
secretMissing: !development && (!secret && !secrets || secret === publicDefaultSecret || secrets?.some((key) => key.value === publicDefaultSecret) === true)
|
|
124
|
+
};
|
|
125
|
+
}
|
|
117
126
|
let derived;
|
|
118
127
|
function hex(buffer) {
|
|
119
128
|
return [...new Uint8Array(buffer)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
120
129
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
* `deriveSecret("vitehub:auth")`. Returns `undefined` when the environment sets a Better Auth secret or no root secret.
|
|
124
|
-
* It is synchronous because Better Auth reads its options synchronously.
|
|
125
|
-
*/
|
|
126
|
-
function deriveAuthSecret(event) {
|
|
127
|
-
const env = {
|
|
128
|
-
...globalThis.process?.env,
|
|
129
|
-
...authCloudflareEnv(event)
|
|
130
|
-
};
|
|
131
|
-
if (betterAuthSecretNames.some((name) => env[name])) return void 0;
|
|
132
|
-
const root = readViteHubSecret(env);
|
|
130
|
+
function deriveAuthSecret(environment) {
|
|
131
|
+
const root = readViteHubSecret(environment);
|
|
133
132
|
if (!root) return void 0;
|
|
134
133
|
if (root.length < 32) throw authErrorDiagnostics.AUTH_R0016({ message: `[vitehub] VITEHUB_SECRET must be at least 32 characters. Generate one with \`openssl rand -base64 32\`.` });
|
|
135
134
|
if (derived?.root !== root) derived = {
|
|
@@ -823,6 +822,72 @@ function withClientAddress(auth) {
|
|
|
823
822
|
fetch: addressedHandler
|
|
824
823
|
});
|
|
825
824
|
}
|
|
825
|
+
// src/rate-limit-endpoints.ts
|
|
826
|
+
const binders = /* @__PURE__ */ new WeakMap();
|
|
827
|
+
function endpointRouter(api) {
|
|
828
|
+
const router = createRouter();
|
|
829
|
+
for (const endpoint of Object.values(api)) {
|
|
830
|
+
const { path, options } = endpoint;
|
|
831
|
+
if (!path || !options) continue;
|
|
832
|
+
if (("metadata" in options ? options.metadata : void 0)?.SERVER_ONLY) continue;
|
|
833
|
+
const methods = Array.isArray(options.method) ? options.method : [options.method];
|
|
834
|
+
for (const method of methods) addRoute(router, method, path, path);
|
|
835
|
+
}
|
|
836
|
+
return router;
|
|
837
|
+
}
|
|
838
|
+
function matchEndpoint(auth) {
|
|
839
|
+
let router;
|
|
840
|
+
return async (request) => {
|
|
841
|
+
const context = await auth.$context;
|
|
842
|
+
const { advanced, baseURL } = context.options;
|
|
843
|
+
const basePath = context.options.basePath || "/api/auth";
|
|
844
|
+
const resolved = isDynamicBaseURLConfig(auth.options.baseURL) ? resolveBaseURL(baseURL, basePath, request, void 0, advanced?.trustedProxyHeaders ?? false) : context.baseURL || getBaseURL(void 0, basePath, request, void 0, advanced?.trustedProxyHeaders);
|
|
845
|
+
if (!resolved) return;
|
|
846
|
+
const mount = trimTrailingSlashes(new URL(resolved).pathname);
|
|
847
|
+
const pathname = new URL(request.url).pathname;
|
|
848
|
+
if (mount && !pathname.startsWith(`${mount}/`)) return;
|
|
849
|
+
const path = pathname.slice(mount.length);
|
|
850
|
+
if (!path || path.includes("//")) return;
|
|
851
|
+
router ??= endpointRouter(auth.api);
|
|
852
|
+
const route = findRoute(router, request.method, path, { params: false })?.data;
|
|
853
|
+
if (!route || !auth.options.advanced?.skipTrailingSlashes && path.endsWith("/") !== route.endsWith("/")) return;
|
|
854
|
+
return !/[:*(){\\]/.test(route) && trimTrailingSlashes(route) === trimTrailingSlashes(path) ? "static" : "pattern";
|
|
855
|
+
};
|
|
856
|
+
}
|
|
857
|
+
/**
|
|
858
|
+
* These rules count a request only when its path is a static endpoint path of the instance, so that each client
|
|
859
|
+
* address has a fixed set of counters. Exact rules of the app apply as declared; wildcard rules also match parameterized endpoints. Each
|
|
860
|
+
* wildcard rule object also stays under a key that no request path matches, because Better Auth reads the windows of
|
|
861
|
+
* rule objects to decide which stored counters have expired.
|
|
862
|
+
* {@link withEndpointRateLimits} gives the rules the endpoints of the instance; until then, every request counts.
|
|
863
|
+
*/
|
|
864
|
+
function endpointRateLimitRules(rules) {
|
|
865
|
+
let match;
|
|
866
|
+
const guard = (rule) => async (request, current) => {
|
|
867
|
+
if (match && !await match(request)) return false;
|
|
868
|
+
return typeof rule === "function" ? rule(request, current) : rule;
|
|
869
|
+
};
|
|
870
|
+
const guarded = {};
|
|
871
|
+
for (const [path, rule] of Object.entries(rules ?? {})) {
|
|
872
|
+
if (!path.includes("*")) {
|
|
873
|
+
guarded[path] = rule;
|
|
874
|
+
continue;
|
|
875
|
+
}
|
|
876
|
+
guarded[path] = guard(rule);
|
|
877
|
+
if (rule && typeof rule === "object") guarded[`vitehub:window:${rule.window}`] = rule;
|
|
878
|
+
}
|
|
879
|
+
if (!Object.hasOwn(guarded, "**")) guarded["**"] = async (request, current) => !match || await match(request) === "static" ? current : false;
|
|
880
|
+
binders.set(guarded, (auth) => {
|
|
881
|
+
match ??= matchEndpoint(auth);
|
|
882
|
+
});
|
|
883
|
+
return guarded;
|
|
884
|
+
}
|
|
885
|
+
/** Give the rules of {@link endpointRateLimitRules} the endpoints of the instance that uses them. */
|
|
886
|
+
function withEndpointRateLimits(auth) {
|
|
887
|
+
const rules = auth.options?.rateLimit?.customRules;
|
|
888
|
+
if (rules) binders.get(rules)?.(auth);
|
|
889
|
+
return auth;
|
|
890
|
+
}
|
|
826
891
|
// src/session-refresh.ts
|
|
827
892
|
/**
|
|
828
893
|
* Runs `session.onRefresh` from the Better Auth `session.update.before` database hook.
|
|
@@ -941,7 +1006,8 @@ function isDevelopmentServer() {
|
|
|
941
1006
|
/**
|
|
942
1007
|
* Better Auth turns its limiter on only when `NODE_ENV` is `production`, and keeps its counters in the memory of the
|
|
943
1008
|
* process unless a `secondaryStorage` is set. Auth turns it on outside a development server, and keeps the counters in
|
|
944
|
-
* the app Database of `authDatabase()`, where every instance and every Auth built for a request sees them.
|
|
1009
|
+
* the app Database of `authDatabase()`, where every instance and every Auth built for a request sees them. It counts
|
|
1010
|
+
* only requests to the endpoints of the instance.
|
|
945
1011
|
*/
|
|
946
1012
|
function withRateLimitDefaults(options, ownsDatabase) {
|
|
947
1013
|
const rateLimit = options.rateLimit;
|
|
@@ -949,6 +1015,7 @@ function withRateLimitDefaults(options, ownsDatabase) {
|
|
|
949
1015
|
return {
|
|
950
1016
|
...rateLimit,
|
|
951
1017
|
enabled: rateLimit?.enabled ?? !isDevelopmentServer(),
|
|
1018
|
+
customRules: endpointRateLimitRules(rateLimit?.customRules),
|
|
952
1019
|
...database ? { storage: "database" } : {}
|
|
953
1020
|
};
|
|
954
1021
|
}
|
|
@@ -956,38 +1023,36 @@ function withRateLimitDefaults(options, ownsDatabase) {
|
|
|
956
1023
|
* Better Auth reads the client IP from `X-Forwarded-For` by default, which a client can set and Cloudflare does not
|
|
957
1024
|
* send. Auth gives it the address that the host reports instead, also with `trustedProxyHeaders`: on the Node host behind a proxy,
|
|
958
1025
|
* `vitehub({ trustProxy: true })` makes that address the last `X-Forwarded-For` value, which the proxy adds.
|
|
1026
|
+
* Better Auth also turns off its Origin and CSRF checks when `TEST` or `NODE_ENV=test` is set, such as in a server that
|
|
1027
|
+
* a Vitest run starts. Auth serves real requests, so only `advanced.disableOriginCheck` turns them off.
|
|
959
1028
|
*/
|
|
960
|
-
function
|
|
961
|
-
|
|
1029
|
+
function withAdvancedDefaults(advanced) {
|
|
1030
|
+
const disableOriginCheck = advanced?.disableOriginCheck ?? false;
|
|
1031
|
+
if (advanced?.ipAddress?.ipAddressHeaders) return {
|
|
1032
|
+
...advanced,
|
|
1033
|
+
disableOriginCheck
|
|
1034
|
+
};
|
|
962
1035
|
return {
|
|
963
1036
|
...advanced,
|
|
1037
|
+
disableOriginCheck,
|
|
964
1038
|
ipAddress: {
|
|
965
1039
|
...advanced?.ipAddress,
|
|
966
1040
|
ipAddressHeaders: [clientAddressHeader]
|
|
967
1041
|
}
|
|
968
1042
|
};
|
|
969
1043
|
}
|
|
970
|
-
const betterAuthSetupVariables = [
|
|
971
|
-
"AUTH_SECRET",
|
|
972
|
-
"BETTER_AUTH_SECRET",
|
|
973
|
-
"BETTER_AUTH_SECRETS",
|
|
974
|
-
"BETTER_AUTH_TRUSTED_ORIGINS"
|
|
975
|
-
];
|
|
976
1044
|
/**
|
|
977
1045
|
* The environment values that an instance for these options uses. Auth reads a value only when the options use it, so
|
|
978
1046
|
* the instance key and the instance read the same values, and a value that the options replace cannot fail a request.
|
|
979
1047
|
*/
|
|
980
1048
|
function readProviderEnvironment(options, event) {
|
|
981
|
-
const
|
|
982
|
-
...globalThis.process?.env,
|
|
983
|
-
...authCloudflareEnv(event)
|
|
984
|
-
};
|
|
1049
|
+
const bindings = authCloudflareEnv(event);
|
|
985
1050
|
return {
|
|
986
1051
|
admins: readAdmins(event),
|
|
987
1052
|
members: readMembers(event),
|
|
988
1053
|
adminClaim: options.adminClaim === false ? void 0 : readAdminClaim(event),
|
|
989
|
-
|
|
990
|
-
|
|
1054
|
+
...resolveAuthSecrets(options, bindings, isDevelopmentServer()),
|
|
1055
|
+
trustedOrigins: bindings?.BETTER_AUTH_TRUSTED_ORIGINS ?? globalThis.process?.env?.BETTER_AUTH_TRUSTED_ORIGINS
|
|
991
1056
|
};
|
|
992
1057
|
}
|
|
993
1058
|
function stripViteHubOptions(definition, options, environment) {
|
|
@@ -1013,6 +1078,7 @@ function stripViteHubOptions(definition, options, environment) {
|
|
|
1013
1078
|
}
|
|
1014
1079
|
const policy = isRecord(access) ? access.policy : void 0;
|
|
1015
1080
|
validateAuthAccessPolicy(policy);
|
|
1081
|
+
validateAuthAccessRouteRoles(access);
|
|
1016
1082
|
if (policy && !storage.database && !storage.secondaryStorage) throw authErrorDiagnostics.AUTH_C0066({ message: "`defineAuth()` access.policy needs a Better Auth `database` or `secondaryStorage` adapter. A session that lives only in a cookie cannot be ended." });
|
|
1017
1083
|
const declaredPlugins = sessionRefresh.plugins ?? rest.plugins ?? [];
|
|
1018
1084
|
const impersonation = declaredPlugins.some((plugin) => plugin.id === "admin");
|
|
@@ -1061,7 +1127,7 @@ function stripViteHubOptions(definition, options, environment) {
|
|
|
1061
1127
|
createRequestLogPlugin()
|
|
1062
1128
|
],
|
|
1063
1129
|
logger: withRequestLogger(rest.logger),
|
|
1064
|
-
advanced:
|
|
1130
|
+
advanced: withAdvancedDefaults(rest.advanced),
|
|
1065
1131
|
rateLimit,
|
|
1066
1132
|
...eventPlugin ? { hooks: {
|
|
1067
1133
|
...rest.hooks,
|
|
@@ -1085,12 +1151,13 @@ function withSessionRefresh(options, hasSessionStore) {
|
|
|
1085
1151
|
session: betterAuthSession
|
|
1086
1152
|
};
|
|
1087
1153
|
}
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
return
|
|
1154
|
+
function withResolvedSecrets(options, { secret, secrets, secretMissing }) {
|
|
1155
|
+
if (secretMissing) throw authErrorDiagnostics.AUTH_SECRET_MISSING();
|
|
1156
|
+
return {
|
|
1091
1157
|
...options,
|
|
1092
|
-
secret
|
|
1093
|
-
|
|
1158
|
+
...secret ? { secret } : {},
|
|
1159
|
+
...secrets ? { secrets } : {}
|
|
1160
|
+
};
|
|
1094
1161
|
}
|
|
1095
1162
|
function trustsProxyHeaders(options) {
|
|
1096
1163
|
return isRecord(options) && isRecord(options.advanced) && options.advanced.trustedProxyHeaders === true;
|
|
@@ -1104,8 +1171,10 @@ function resolveAuthOptions(definition, input = {}) {
|
|
|
1104
1171
|
const callback = typeof definition.options === "function";
|
|
1105
1172
|
const usesContext = !request || callback;
|
|
1106
1173
|
const env = usesContext ? input.env?.(input.event) ?? {} : {};
|
|
1107
|
-
const
|
|
1108
|
-
const
|
|
1174
|
+
const client = request && clientRequest(request);
|
|
1175
|
+
const publicOrigin = client ? configuredAppOrigin(client) : void 0;
|
|
1176
|
+
const clientUrlOrigin = client ? publicOrigin ?? new URL(client.url).origin : void 0;
|
|
1177
|
+
const proxiedOrigin = client ? publicOrigin ?? forwardedRequestOrigin(client) : void 0;
|
|
1109
1178
|
const resolveAt = (origin) => {
|
|
1110
1179
|
const context = {
|
|
1111
1180
|
env,
|
|
@@ -1119,8 +1188,8 @@ function resolveAuthOptions(definition, input = {}) {
|
|
|
1119
1188
|
trusted: trustsProxyHeaders(declared)
|
|
1120
1189
|
};
|
|
1121
1190
|
};
|
|
1122
|
-
let resolved = resolveAt(
|
|
1123
|
-
if (request && callback && resolved.trusted && proxiedOrigin !==
|
|
1191
|
+
let resolved = resolveAt(clientUrlOrigin);
|
|
1192
|
+
if (request && callback && resolved.trusted && proxiedOrigin !== clientUrlOrigin) {
|
|
1124
1193
|
const forwarded = resolveAt(proxiedOrigin);
|
|
1125
1194
|
resolved = forwarded.trusted ? forwarded : {
|
|
1126
1195
|
trusted: false,
|
|
@@ -1135,9 +1204,9 @@ function resolveAuthOptions(definition, input = {}) {
|
|
|
1135
1204
|
}
|
|
1136
1205
|
const { declared, trusted } = resolved;
|
|
1137
1206
|
let requestRuntimeOptions = callback ? declared : {};
|
|
1138
|
-
if (
|
|
1139
|
-
const requestOrigin = trusted && proxiedOrigin ? proxiedOrigin :
|
|
1140
|
-
const baseURL = requestRuntimeOptions.baseURL || resolvePublicUrl({ request: { url: requestOrigin } });
|
|
1207
|
+
if (client) {
|
|
1208
|
+
const requestOrigin = trusted && proxiedOrigin ? proxiedOrigin : client.url;
|
|
1209
|
+
const baseURL = requestRuntimeOptions.baseURL || publicOrigin || resolvePublicUrl({ request: { url: requestOrigin } });
|
|
1141
1210
|
if (!baseURL) throw authErrorDiagnostics.AUTH_R0022({ message: `[vitehub] The request host ${new URL(requestOrigin).host} is not an origin of vitehub({ publicUrl }), so Auth has no base URL.` });
|
|
1142
1211
|
requestRuntimeOptions = {
|
|
1143
1212
|
...!Object.hasOwn(declared, "trustedOrigins") ? { trustedOrigins: [baseURL] } : {},
|
|
@@ -1159,7 +1228,7 @@ function resolveAuthOptions(definition, input = {}) {
|
|
|
1159
1228
|
get providerOptions() {
|
|
1160
1229
|
const options = resolveSnapshot();
|
|
1161
1230
|
const environment = resolveEnvironment();
|
|
1162
|
-
return
|
|
1231
|
+
return withResolvedSecrets(withPasswordHasher(stripViteHubOptions(definition, options, environment)), environment);
|
|
1163
1232
|
},
|
|
1164
1233
|
/** Equal for two resolutions of this Definition that give Better Auth equal options, else `undefined`. */
|
|
1165
1234
|
get providerKey() {
|
|
@@ -1294,7 +1363,7 @@ function hasRequestRuntimeOptions(definition) {
|
|
|
1294
1363
|
return typeof definition.options === "function" || trustsProxyHeaders(definition.options);
|
|
1295
1364
|
}
|
|
1296
1365
|
function hasConfiguredPublicUrl() {
|
|
1297
|
-
return
|
|
1366
|
+
return configuredPublicOrigins().length > 0;
|
|
1298
1367
|
}
|
|
1299
1368
|
function envResolverFor(definition) {
|
|
1300
1369
|
return getAuthRuntimeState().envResolvers?.get(definition) ?? getAuthRuntimeState().envResolver;
|
|
@@ -1315,7 +1384,7 @@ function createBetterAuthOptions(definition) {
|
|
|
1315
1384
|
}
|
|
1316
1385
|
function createAuthenticationProvider(options) {
|
|
1317
1386
|
try {
|
|
1318
|
-
return withSessionMarker(withClientAddress(betterAuth(options)));
|
|
1387
|
+
return withSessionMarker(withEndpointRateLimits(withClientAddress(betterAuth(options))));
|
|
1319
1388
|
} catch (cause) {
|
|
1320
1389
|
throwAuthenticationProviderError(cause, "get-auth-for-request");
|
|
1321
1390
|
}
|
|
@@ -1364,11 +1433,11 @@ function requestProvider(definition, resolved) {
|
|
|
1364
1433
|
* `useAuth(event)`. The Console reads it through `@vite-hub/auth/runtime/console`.
|
|
1365
1434
|
*/
|
|
1366
1435
|
function authForRequest(request, event, definition = resolveDefaultDefinition()) {
|
|
1367
|
-
if (!hasRequestRuntimeOptions(definition) && !hasConfiguredPublicUrl()) return getAuthForDefinition(definition);
|
|
1436
|
+
if (!hasRequestRuntimeOptions(definition) && !hasConfiguredPublicUrl() && (!isDevelopmentServer() || getBaseURL())) return getAuthForDefinition(definition);
|
|
1368
1437
|
return requestProvider(definition, resolveAuthOptions(definition, {
|
|
1369
1438
|
request,
|
|
1370
1439
|
event,
|
|
1371
1440
|
env: envResolverFor(definition)
|
|
1372
1441
|
}));
|
|
1373
1442
|
}
|
|
1374
|
-
export {
|
|
1443
|
+
export { setAuthResponseOutcome as _, getAuthForDefinition as a, withSessionMarker as c, withEndpointRateLimits as d, eventClientAddress as f, setAuthOutcome as g, runWithAuthEvent as h, findVerifiedAuthUserId as i, resolveAuthOptions as l, withClientAddress as m, createBetterAuthOptions as n, requestProvider as o, setRequestClientAddress as p, envResolverFor as r, resolveDefaultDefinition as s, authForRequest as t, trustsProxyHeaders as u };
|
|
@@ -58,6 +58,7 @@ interface ProvisionStep {
|
|
|
58
58
|
id: string;
|
|
59
59
|
provider: ProvisionProvider;
|
|
60
60
|
plan: (context: ProvisionContext) => Promise<ProvisionAction[]>;
|
|
61
|
+
hasResources?: (context: Pick<ProvisionContext, "env">) => boolean;
|
|
61
62
|
/** Describes the Provision State this step records. Runs without network access, also without credentials. */
|
|
62
63
|
recordedState?: (context: Pick<ProvisionContext, "env">) => ProvisionStateCategory[];
|
|
63
64
|
}
|
|
@@ -74,10 +75,13 @@ interface ViteHubCliSpawnResult {
|
|
|
74
75
|
signal?: NodeJS.Signals | null;
|
|
75
76
|
/** The output of the child when `stdout` is `pipe`. */
|
|
76
77
|
stdout?: string;
|
|
78
|
+
/** The error output of the child when `stderr` is `pipe`. */
|
|
79
|
+
stderr?: string;
|
|
77
80
|
}
|
|
78
81
|
interface ViteHubCliSpawnOptions {
|
|
79
82
|
cwd?: string;
|
|
80
83
|
env?: NodeJS.ProcessEnv;
|
|
84
|
+
onOutput?: (text: string, stream: "stdout" | "stderr") => void;
|
|
81
85
|
stderr?: "inherit" | "pipe";
|
|
82
86
|
/** `ignore` gives the child no terminal input, so a tool that asks questions on a terminal does not ask. */
|
|
83
87
|
stdin?: "ignore" | "inherit";
|
|
@@ -85,7 +89,17 @@ interface ViteHubCliSpawnOptions {
|
|
|
85
89
|
stdout?: "inherit" | "pipe" | "stderr";
|
|
86
90
|
}
|
|
87
91
|
type ViteHubCliSpawn = (command: string, args: string[], options?: ViteHubCliSpawnOptions) => Promise<ViteHubCliSpawnResult>;
|
|
92
|
+
/** Where a call to an app goes through the Console: the operation endpoint of the app's Console project, and the token of `vitehub login`. */
|
|
93
|
+
interface ViteHubCliConsoleRoute {
|
|
94
|
+
authorization: string;
|
|
95
|
+
target: string;
|
|
96
|
+
}
|
|
88
97
|
interface ViteHubCliContext extends ViteHubCliStreams {
|
|
98
|
+
/**
|
|
99
|
+
* Finds the app at `url` in the Console of `vitehub login` and returns the route that lets the Console sign the call.
|
|
100
|
+
* Returns nothing when the command must call the app directly, such as when a `VITEHUB_CONSOLE_PRIVATE_KEY_<NAME>` is set.
|
|
101
|
+
*/
|
|
102
|
+
consoleRoute?: (url: string, signal: AbortSignal) => Promise<ViteHubCliConsoleRoute | undefined>;
|
|
89
103
|
cwd: string;
|
|
90
104
|
env: NodeJS.ProcessEnv;
|
|
91
105
|
/** Replaces `fetch` for commands that call a running app, so tests need no server. */
|
|
@@ -104,6 +118,7 @@ interface ViteHubCliContext extends ViteHubCliStreams {
|
|
|
104
118
|
spawn: ViteHubCliSpawn;
|
|
105
119
|
}
|
|
106
120
|
interface ViteHubCliProvision {
|
|
121
|
+
env?: NodeJS.ProcessEnv;
|
|
107
122
|
rootDir: string;
|
|
108
123
|
steps: readonly ProvisionStep[];
|
|
109
124
|
}
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as ViteHubCliContributor } from "./cli-
|
|
1
|
+
import { t as ViteHubCliContributor } from "./cli-DL7uCAvz.js";
|
|
2
2
|
/** Read the app-owned, session-protected endpoint. No local or remote database credentials are needed. */
|
|
3
3
|
export declare function createAuthCliContributor(options?: {
|
|
4
4
|
fetch?: typeof fetch;
|
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as adminClaimVariable, r as createAdminClaimCode, t as adminClaimHash } from "./admin-claim-code-C3X_U43x.js";
|
|
2
|
-
import { t as authErrorDiagnostics } from "./error-diagnostics-
|
|
2
|
+
import { t as authErrorDiagnostics } from "./error-diagnostics-DkzL9ltR.js";
|
|
3
3
|
// src/cli.ts
|
|
4
4
|
const usage = "vitehub auth events --url <auth-base-url> [--type <type>] [--user <id>] [--actor <actor>] [--from <ISO>] [--to <ISO>] [--cursor <cursor>] [--limit <1-200>] [--aggregate]";
|
|
5
5
|
/** Read the app-owned, session-protected endpoint. No local or remote database credentials are needed. */
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
// ../internal/src/runtime/request-origin.ts
|
|
3
|
+
function firstHeaderValue(headers, name) {
|
|
4
|
+
return headers.get(name)?.split(",", 1)[0]?.trim() || void 0;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* The origin that the client used for `request`. A TLS-terminating proxy sends the client scheme in
|
|
8
|
+
* `X-Forwarded-Proto` and the client host in `X-Forwarded-Host`. Each proxy appends its value, so the first value wins.
|
|
9
|
+
* Without these headers, or with values that are not valid, the result is the origin of `request.url`.
|
|
10
|
+
*/
|
|
11
|
+
function forwardedRequestOrigin(request) {
|
|
12
|
+
const url = new URL(request.url);
|
|
13
|
+
const forwardedProtocol = firstHeaderValue(request.headers, "x-forwarded-proto")?.toLowerCase();
|
|
14
|
+
const protocol = forwardedProtocol === "http" || forwardedProtocol === "https" ? forwardedProtocol : url.protocol.slice(0, -1);
|
|
15
|
+
const host = firstHeaderValue(request.headers, "x-forwarded-host") ?? url.host;
|
|
16
|
+
if (/[\u0000-\u001F\s/\\?#@]/.test(host)) return url.origin;
|
|
17
|
+
try {
|
|
18
|
+
return new URL(`${protocol}://${host}`).origin;
|
|
19
|
+
} catch {
|
|
20
|
+
return url.origin;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
// src/client-request.ts
|
|
24
|
+
const storageKey = Symbol.for("vitehub.auth.client-request");
|
|
25
|
+
const runtimeGlobal = globalThis;
|
|
26
|
+
const clientRequests = runtimeGlobal[storageKey] ||= new AsyncLocalStorage();
|
|
27
|
+
function isRelativeInProcessRequest(request, client) {
|
|
28
|
+
const url = new URL(request.url);
|
|
29
|
+
if (url.protocol !== "http:") return false;
|
|
30
|
+
if (url.host === "localhost") return true;
|
|
31
|
+
const clientUrl = new URL(client.url);
|
|
32
|
+
url.protocol = clientUrl.protocol;
|
|
33
|
+
return url.host === clientUrl.host;
|
|
34
|
+
}
|
|
35
|
+
function runWithClientRequest(request, next) {
|
|
36
|
+
const client = clientRequests.getStore();
|
|
37
|
+
return client && isRelativeInProcessRequest(request, client) ? next() : clientRequests.run(request, next);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Nitro builds a relative request that the server sends to itself, such as a Nuxt `useFetch()` during server rendering
|
|
41
|
+
* or `serverFetch("/api/...")`, at `http://localhost` or `http://<forwarded Host>`, so the URL of that request does not
|
|
42
|
+
* show the origin of the page.
|
|
43
|
+
*/
|
|
44
|
+
function clientRequest(request) {
|
|
45
|
+
const client = clientRequests.getStore();
|
|
46
|
+
return client && isRelativeInProcessRequest(request, client) ? client : request;
|
|
47
|
+
}
|
|
48
|
+
function clientRequestOrigin(request, trustProxyHeaders = false) {
|
|
49
|
+
const client = clientRequest(request);
|
|
50
|
+
return trustProxyHeaders ? forwardedRequestOrigin(client) : new URL(client.url).origin;
|
|
51
|
+
}
|
|
52
|
+
export { forwardedRequestOrigin as i, clientRequestOrigin as n, runWithClientRequest as r, clientRequest as t };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { d as adminsVariable, m as accessPolicyPluginId, r as membersVariable, s as adminClaimPluginId, u as adminsPluginId } from "./members-CRlYyxVk.js";
|
|
2
2
|
import { n as adminClaimVariable } from "./admin-claim-code-C3X_U43x.js";
|
|
3
3
|
import { n as authConsoleEventGroups, t as authConsoleActionNames } from "./console-types-NrX5TWl3.js";
|
|
4
|
-
import { r as parseAuthEventList } from "./events-
|
|
4
|
+
import { r as parseAuthEventList } from "./events-BUaoHFoC.js";
|
|
5
5
|
import { defineErrors } from "@vite-hub/runtime";
|
|
6
6
|
import { defineGrant } from "@vite-hub/runtime/internal/grant";
|
|
7
7
|
// ../internal/src/runtime/user-agent.ts
|
|
@@ -194,7 +194,9 @@ function adminsAccess(plugins) {
|
|
|
194
194
|
const admins = Reflect.get(options, "admins");
|
|
195
195
|
const role = Reflect.get(options, "role");
|
|
196
196
|
if (!Array.isArray(admins) || typeof role !== "string") return [];
|
|
197
|
-
|
|
197
|
+
const emails = admins.filter((entry) => typeof entry === "string" && entry.includes("@")).length;
|
|
198
|
+
const listed = [...admins.filter((entry) => typeof entry === "string" && !entry.includes("@")), ...emails ? [`${emails} verified ${emails === 1 ? "email" : "emails"}`] : []];
|
|
199
|
+
return [`${adminsVariable} gives the ${role} role to ${listed.join(", ")} on sign-in.`];
|
|
198
200
|
}
|
|
199
201
|
/** The `VITEHUB_MEMBERS` rule as an access note, so the Console shows who may sign in. */
|
|
200
202
|
function membersAccess(plugins) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { J as AuthConsoleAgent, K as AuthConsoleActivity, Lt as AuthEventStore, Z as AuthConsoleDescription, _t as AuthConsoleSessionUser, ct as AuthConsoleOptions, dt as AuthConsoleOverview, gt as AuthConsoleSession, it as AuthConsoleHostOptions, lt as AuthConsoleOrganization, mt as AuthConsoleQuery, ot as AuthConsoleList, q as AuthConsoleActivityQuery, st as AuthConsoleMutation, tt as AuthConsoleField, ut as AuthConsoleOrganizationDetail, vt as AuthConsoleUser, yt as AuthConsoleUserDetail } from "./types-BmRGse4l.js";
|
|
2
2
|
import { Result } from "@vite-hub/runtime";
|
|
3
3
|
import { AuthContext, BetterAuthOptions, DBAdapter } from "better-auth";
|
|
4
4
|
interface AuthConsole {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { $ as AuthConsoleEventGroup, G as AuthConsoleAction, J as AuthConsoleAgent, K as AuthConsoleActivity, Q as AuthConsoleEvent, St as authConsoleEventGroups, X as AuthConsoleColumn, Y as AuthConsoleCapability, Z as AuthConsoleDescription, _t as AuthConsoleSessionUser, at as AuthConsoleImpersonation, bt as AuthConsoleValue, ct as AuthConsoleOptions, dt as AuthConsoleOverview, et as AuthConsoleEventUser, ft as AuthConsolePage, gt as AuthConsoleSession, ht as AuthConsoleRoles, it as AuthConsoleHostOptions, lt as AuthConsoleOrganization, mt as AuthConsoleQuery, nt as AuthConsoleFieldPolicy, ot as AuthConsoleList, pt as AuthConsolePolicy, q as AuthConsoleActivityQuery, rt as AuthConsoleFieldType, st as AuthConsoleMutation, tt as AuthConsoleField, ut as AuthConsoleOrganizationDetail, vt as AuthConsoleUser, xt as authConsoleActionNames, yt as AuthConsoleUserDetail } from "./types-
|
|
2
|
-
import { i as describeAuthConsoleFields, n as AuthConsoleErrorCode, r as createAuthConsole, t as AuthConsole } from "./console-runtime-
|
|
1
|
+
import { $ as AuthConsoleEventGroup, G as AuthConsoleAction, J as AuthConsoleAgent, K as AuthConsoleActivity, Q as AuthConsoleEvent, St as authConsoleEventGroups, X as AuthConsoleColumn, Y as AuthConsoleCapability, Z as AuthConsoleDescription, _t as AuthConsoleSessionUser, at as AuthConsoleImpersonation, bt as AuthConsoleValue, ct as AuthConsoleOptions, dt as AuthConsoleOverview, et as AuthConsoleEventUser, ft as AuthConsolePage, gt as AuthConsoleSession, ht as AuthConsoleRoles, it as AuthConsoleHostOptions, lt as AuthConsoleOrganization, mt as AuthConsoleQuery, nt as AuthConsoleFieldPolicy, ot as AuthConsoleList, pt as AuthConsolePolicy, q as AuthConsoleActivityQuery, rt as AuthConsoleFieldType, st as AuthConsoleMutation, tt as AuthConsoleField, ut as AuthConsoleOrganizationDetail, vt as AuthConsoleUser, xt as authConsoleActionNames, yt as AuthConsoleUserDetail } from "./types-BmRGse4l.js";
|
|
2
|
+
import { i as describeAuthConsoleFields, n as AuthConsoleErrorCode, r as createAuthConsole, t as AuthConsole } from "./console-runtime-XcplYv4R.js";
|
|
3
3
|
export { AuthConsole, type AuthConsoleAction, type AuthConsoleActivity, type AuthConsoleActivityQuery, type AuthConsoleAgent, type AuthConsoleCapability, type AuthConsoleColumn, type AuthConsoleDescription, AuthConsoleErrorCode, type AuthConsoleEvent, type AuthConsoleEventGroup, type AuthConsoleEventUser, type AuthConsoleField, type AuthConsoleFieldPolicy, type AuthConsoleFieldType, type AuthConsoleHostOptions, type AuthConsoleImpersonation, type AuthConsoleList, type AuthConsoleMutation, type AuthConsoleOptions, type AuthConsoleOrganization, type AuthConsoleOrganizationDetail, type AuthConsoleOverview, type AuthConsolePage, type AuthConsolePolicy, type AuthConsoleQuery, type AuthConsoleRoles, type AuthConsoleSession, type AuthConsoleSessionUser, type AuthConsoleUser, type AuthConsoleUserDetail, type AuthConsoleValue, type authConsoleActionNames, type authConsoleEventGroups, createAuthConsole, describeAuthConsoleFields };
|
package/dist/console-runtime.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as createAuthConsole, n as describeAuthConsoleFields } from "./console-runtime-
|
|
1
|
+
export { t as createAuthConsole, n as describeAuthConsoleFields } from "./console-runtime-Bg_PAl7e.js";
|
package/dist/console.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as AuthConsoleEventGroup, G as AuthConsoleAction, J as AuthConsoleAgent, K as AuthConsoleActivity, Q as AuthConsoleEvent, St as authConsoleEventGroups, X as AuthConsoleColumn, Y as AuthConsoleCapability, Z as AuthConsoleDescription, _t as AuthConsoleSessionUser, at as AuthConsoleImpersonation, bt as AuthConsoleValue, ct as AuthConsoleOptions, dt as AuthConsoleOverview, et as AuthConsoleEventUser, ft as AuthConsolePage, gt as AuthConsoleSession, ht as AuthConsoleRoles, it as AuthConsoleHostOptions, lt as AuthConsoleOrganization, mt as AuthConsoleQuery, nt as AuthConsoleFieldPolicy, ot as AuthConsoleList, pt as AuthConsolePolicy, q as AuthConsoleActivityQuery, rt as AuthConsoleFieldType, st as AuthConsoleMutation, tt as AuthConsoleField, ut as AuthConsoleOrganizationDetail, vt as AuthConsoleUser, xt as authConsoleActionNames, yt as AuthConsoleUserDetail } from "./types-
|
|
1
|
+
import { $ as AuthConsoleEventGroup, G as AuthConsoleAction, J as AuthConsoleAgent, K as AuthConsoleActivity, Q as AuthConsoleEvent, St as authConsoleEventGroups, X as AuthConsoleColumn, Y as AuthConsoleCapability, Z as AuthConsoleDescription, _t as AuthConsoleSessionUser, at as AuthConsoleImpersonation, bt as AuthConsoleValue, ct as AuthConsoleOptions, dt as AuthConsoleOverview, et as AuthConsoleEventUser, ft as AuthConsolePage, gt as AuthConsoleSession, ht as AuthConsoleRoles, it as AuthConsoleHostOptions, lt as AuthConsoleOrganization, mt as AuthConsoleQuery, nt as AuthConsoleFieldPolicy, ot as AuthConsoleList, pt as AuthConsolePolicy, q as AuthConsoleActivityQuery, rt as AuthConsoleFieldType, st as AuthConsoleMutation, tt as AuthConsoleField, ut as AuthConsoleOrganizationDetail, vt as AuthConsoleUser, xt as authConsoleActionNames, yt as AuthConsoleUserDetail } from "./types-BmRGse4l.js";
|
|
2
2
|
/** Lists discovered Definitions in a sidebar and shows the selected Definition's fields. */
|
|
3
3
|
interface ViteHubConsoleDefinitionCatalogView {
|
|
4
4
|
kind: "definition-catalog";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as authErrorDiagnostics } from "./error-diagnostics-
|
|
1
|
+
import { t as authErrorDiagnostics } from "./error-diagnostics-DkzL9ltR.js";
|
|
2
2
|
// src/database-options.ts
|
|
3
3
|
/** Reads the adapter's target without loading Better Auth or the Database runtime. */
|
|
4
4
|
function authDatabaseName(database) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as authDatabaseSchemaError } from "./database-options-
|
|
1
|
+
import { a as authDatabaseSchemaError } from "./database-options-DE9lMwu1.js";
|
|
2
2
|
import { getAuthTables } from "better-auth/db";
|
|
3
3
|
// src/database-schema-options.ts
|
|
4
4
|
/** Better Auth reads each table by its key and each column by its field key, so the options must not rename them. */
|
package/dist/database.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { f as AuthAppDatabase } from "./types-
|
|
1
|
+
import { f as AuthAppDatabase } from "./types-BmRGse4l.js";
|
|
2
2
|
/**
|
|
3
3
|
* The Better Auth `database` adapter for the app Database `name` (default `"default"`). Pass it inline as the
|
|
4
4
|
* `database` of `defineAuth()`. Auth then adds the Better Auth tables, the fields of `admin()` when the Definition calls it, the
|
package/dist/database.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as authErrorDiagnostics } from "./error-diagnostics-
|
|
2
|
-
import { a as authDatabaseSchemaError, t as assertAuthDatabaseIdStrategy } from "./database-options-
|
|
3
|
-
import { t as assertAuthDatabaseNames } from "./database-schema-options-
|
|
1
|
+
import { t as authErrorDiagnostics } from "./error-diagnostics-DkzL9ltR.js";
|
|
2
|
+
import { a as authDatabaseSchemaError, t as assertAuthDatabaseIdStrategy } from "./database-options-DE9lMwu1.js";
|
|
3
|
+
import { t as assertAuthDatabaseNames } from "./database-schema-options-CCQsNhjc.js";
|
|
4
4
|
import { getAuthTables } from "better-auth/db";
|
|
5
5
|
import { getTableColumns, is, isTable } from "drizzle-orm";
|
|
6
6
|
import { drizzleAdapter } from "better-auth/adapters/drizzle";
|
|
@@ -32,7 +32,7 @@ function authDatabase(name = "default") {
|
|
|
32
32
|
assertAuthDatabaseIdStrategy(options.advanced?.database?.generateId);
|
|
33
33
|
assertAuthDatabaseNames(options);
|
|
34
34
|
const entry = Object.hasOwn(databases, name) ? databases[name] : void 0;
|
|
35
|
-
if (!entry || !Object.hasOwn(entry.schema, "user")) throw authErrorDiagnostics.AUTH_R0019({ message: `[vitehub] \`authDatabase(${JSON.stringify(name)})\` found no Better Auth tables in the ${JSON.stringify(name)} Database. Pass \`authDatabase()\` inline as the \`database\` of \`defineAuth()\` so that Auth adds them,
|
|
35
|
+
if (!entry || !Object.hasOwn(entry.schema, "user")) throw authErrorDiagnostics.AUTH_R0019({ message: `[vitehub] \`authDatabase(${JSON.stringify(name)})\` found no Better Auth tables in the ${JSON.stringify(name)} Database. Pass \`authDatabase()\` inline as the \`database\` of \`defineAuth()\` so that Auth adds them, then run \`vitehub database generate\` and \`vitehub database migrate\`. \`vitehub inspect definitions --kind database\` lists the tables of each Database.` });
|
|
36
36
|
assertAuthDatabaseSchema(options, entry.schema, name);
|
|
37
37
|
return drizzleAdapter(entry.db, {
|
|
38
38
|
provider: is(entry.db, PgAsyncDatabase) ? "pg" : "sqlite",
|