@vite-hub/auth 0.7.0 → 0.9.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.
Files changed (78) hide show
  1. package/README.md +59 -6
  2. package/dist/{abilities-CfvuGrBv.d.ts → abilities-6LE7VSdN.d.ts} +1 -1
  3. package/dist/abilities.d.ts +1 -1
  4. package/dist/{ability-error-OKoyOwPM.js → ability-error-Ccm5Iy4F.js} +1 -1
  5. package/dist/{access-pages-Bej95blM.js → access-pages-lQGfRvfL.js} +1 -4
  6. package/dist/{admin-claim-code-C3X_U43x.js → admin-claim-code-CMa0eRRm.js} +0 -1
  7. package/dist/agent.js +11 -11
  8. package/dist/{application-path-zKi7NrvK.js → application-path-LMc_ptL9.js} +0 -2
  9. package/dist/{auth-instance-5RSiFTDC.js → auth-instance-0PTsOttV.js} +41 -57
  10. package/dist/bun-sqlite.d.ts +0 -2
  11. package/dist/cli.js +2 -2
  12. package/dist/client-extension-BVBVUqa1.d.ts +33 -0
  13. package/dist/client-request-B1DCz3a9.js +29 -0
  14. package/dist/{console-runtime-Bg_PAl7e.js → console-runtime-BlOx9hWC.js} +3 -19
  15. package/dist/{console-runtime-XcplYv4R.d.ts → console-runtime-D2FUATXQ.d.ts} +1 -1
  16. package/dist/console-runtime.d.ts +2 -2
  17. package/dist/console-runtime.js +1 -1
  18. package/dist/console.d.ts +1 -1
  19. package/dist/database-options-CPhnGap9.js +36 -0
  20. package/dist/{database-schema-options-CCQsNhjc.js → database-schema-options-BQyynyhw.js} +1 -1
  21. package/dist/database.d.ts +1 -1
  22. package/dist/database.js +22 -11
  23. package/dist/{definition-DeEeqTLC.js → definition-CvmvHaQT.js} +4 -12
  24. package/dist/{error-diagnostics-DkzL9ltR.js → error-diagnostics-BpQy1iIO.js} +35 -4
  25. package/dist/{events-BUaoHFoC.js → events-aP_Rz_gx.js} +1 -1
  26. package/dist/extension-B35v_o1u.js +133 -0
  27. package/dist/extension-C2giF7w2.d.ts +59 -0
  28. package/dist/forward.d.ts +0 -5
  29. package/dist/forward.js +1 -1
  30. package/dist/index.d.ts +4 -3
  31. package/dist/index.js +4 -3
  32. package/dist/internal/server.d.ts +3 -3
  33. package/dist/internal/server.js +5 -5
  34. package/dist/{mcp-config-C7srUMIZ.js → mcp-config-DYlTXmr6.js} +9 -1
  35. package/dist/{mcp-token-DG1jmw4o.d.ts → mcp-token-CxpopXmK.d.ts} +4 -2
  36. package/dist/{mcp-token-DgveSGEl.js → mcp-token-i-8NMulH.js} +28 -6
  37. package/dist/mcp.d.ts +2 -7
  38. package/dist/mcp.js +26 -7
  39. package/dist/{members-CRlYyxVk.js → members-USm08YwK.js} +4 -6
  40. package/dist/nuxt.d.ts +4 -14
  41. package/dist/nuxt.js +29 -61
  42. package/dist/{own-access-BvVUjaeL.d.ts → own-access-B7VRd92K.d.ts} +1 -1
  43. package/dist/presets.js +1 -1
  44. package/dist/{request-Dpq7GO8B.js → request-CdlcvqVc.js} +0 -1
  45. package/dist/runtime/client-request-plugin.d.ts +2 -1
  46. package/dist/runtime/client-request-plugin.js +8 -5
  47. package/dist/runtime/console.d.ts +1 -1
  48. package/dist/runtime/console.js +2 -2
  49. package/dist/runtime/empty-abilities.d.ts +1 -1
  50. package/dist/runtime/empty-client.d.ts +3 -0
  51. package/dist/runtime/empty-client.js +3 -1
  52. package/dist/runtime/empty-definition.d.ts +1 -1
  53. package/dist/runtime/server.d.ts +4 -3
  54. package/dist/runtime/server.js +5 -4
  55. package/dist/runtime/vue-nuxt.js +2 -18
  56. package/dist/schema.d.ts +32 -17
  57. package/dist/schema.js +39 -16
  58. package/dist/{server-1G_BbfBD.d.ts → server-4_EXgXFn.d.ts} +25 -8
  59. package/dist/{server-iQNOXyfS.js → server-CZR2dVVp.js} +43 -352
  60. package/dist/{server-B8kTFrHP.d.ts → server-DAIBBKbR.d.ts} +3 -2
  61. package/dist/server.d.ts +3 -3
  62. package/dist/server.js +4 -4
  63. package/dist/{session-cookies-DN0svCKj.js → session-cookies-CfXdF1yd.js} +5 -33
  64. package/dist/{set-cookie-CMB3t4NF.js → set-cookie-BYZslovs.js} +1 -1
  65. package/dist/{table-specs-C3-bLOSF.js → table-specs-Cvjc_Ccs.js} +28 -2
  66. package/dist/{table-specs-P4LvbOlX.d.ts → table-specs-VYAy_jJ7.d.ts} +5 -2
  67. package/dist/test.d.ts +1 -1
  68. package/dist/test.js +2 -2
  69. package/dist/{types-BmRGse4l.d.ts → types-DakualFJ.d.ts} +20 -4
  70. package/dist/vite-CZ_Z6IR3.d.ts +28 -0
  71. package/dist/{vite-GRzej8Cs.js → vite-DVvWaN3D.js} +652 -301
  72. package/dist/vite.d.ts +35 -17
  73. package/dist/vite.js +1 -1
  74. package/dist/vue.d.ts +4 -34
  75. package/dist/vue.js +40 -66
  76. package/package.json +9 -8
  77. package/dist/client-request-BzMKtfCY.js +0 -52
  78. package/dist/database-options-DE9lMwu1.js +0 -28
@@ -1,5 +1,5 @@
1
1
  /// <reference path="../host-declarations.d.ts" />
2
- import { A as sendSessionCookies, C as requireCaller, D as withAnonymousAuthorization, E as useAuth, M as createBetterAuthOptions, N as findVerifiedAuthUserId, O as withAuth, P as getAuthForDefinition, S as requireAuthorization, T as toAuthRequest, _ as handleAuthRequest, a as authRoute, b as requireAuth, c as createAuth, d as createAuthHandler, f as createAuthRequestRuntimeOptions, g as handleAuth, h as getAuthEvents, i as assertAuthOrigin, k as withAuthorization, l as createAuthAccessHandler, m as getAuthConsoleForRequest, n as AuthSignOutOptions, o as can, p as getAuth, r as aggregateAuthEvents, s as checkAuthMember, t as AuthEventReadErrorCode, u as createAuthForRequest, v as listAuthEvents, w as signOut, x as requireAuthAccessRoutes, y as requireAbility } from "../server-1G_BbfBD.js";
3
- import { a as setAuthAccessIdentityResolver, o as setAuthRuntimeEnvResolver, s as resetAuth } from "../server-B8kTFrHP.js";
2
+ import { A as withAuthorization, C as requireAuthorization, D as useAuth, E as toAuthRequest, F as getAuthForDefinition, N as createBetterAuthOptions, O as withAnonymousAuthorization, P as findVerifiedAuthUserId, S as requireAuthAccessRoutes, T as signOut, _ as handleAuth, a as authMiddleware, b as requireAbility, c as checkAuthMember, d as createAuthForRequest, f as createAuthHandler, g as getAuthEvents, h as getAuthConsoleForRequest, i as assertAuthOrigin, j as sendSessionCookies, k as withAuth, l as createAuth, m as getAuth, n as AuthSignOutOptions, o as authRoute, p as createAuthRequestRuntimeOptions, r as aggregateAuthEvents, s as can, t as AuthEventReadErrorCode, u as createAuthAccessHandler, v as handleAuthRequest, w as requireCaller, x as requireAuth, y as listAuthEvents } from "../server-4_EXgXFn.js";
3
+ import { a as setAuthAccessIdentityResolver, o as setAuthRuntimeEnvResolver, s as resetAuth } from "../server-DAIBBKbR.js";
4
4
  import { n as AbilityErrorData, t as AbilityError } from "../ability-error-C1c30O6E.js";
5
- export { AbilityError, type AbilityErrorData, AuthEventReadErrorCode, AuthSignOutOptions, aggregateAuthEvents, assertAuthOrigin, can, checkAuthMember, createAuth, createAuthAccessHandler, createAuthForRequest, createAuthHandler, createAuthRequestRuntimeOptions, createBetterAuthOptions, authRoute as default, findVerifiedAuthUserId, getAuth, getAuthConsoleForRequest, getAuthEvents, getAuthForDefinition, handleAuth, handleAuthRequest, listAuthEvents, requireAbility, requireAuth, requireAuthAccessRoutes, requireAuthorization, requireCaller, resetAuth, sendSessionCookies, setAuthAccessIdentityResolver, setAuthRuntimeEnvResolver, signOut, toAuthRequest, useAuth, withAnonymousAuthorization, withAuth, withAuthorization };
5
+ export { AbilityError, type AbilityErrorData, AuthEventReadErrorCode, AuthSignOutOptions, aggregateAuthEvents, assertAuthOrigin, authMiddleware, can, checkAuthMember, createAuth, createAuthAccessHandler, createAuthForRequest, createAuthHandler, createAuthRequestRuntimeOptions, createBetterAuthOptions, authRoute as default, findVerifiedAuthUserId, getAuth, getAuthConsoleForRequest, getAuthEvents, getAuthForDefinition, handleAuth, handleAuthRequest, listAuthEvents, requireAbility, requireAuth, requireAuthAccessRoutes, requireAuthorization, requireCaller, resetAuth, sendSessionCookies, setAuthAccessIdentityResolver, setAuthRuntimeEnvResolver, signOut, toAuthRequest, useAuth, withAnonymousAuthorization, withAuth, withAuthorization };
@@ -1,7 +1,7 @@
1
- import { n as sendSessionCookies } from "../session-cookies-DN0svCKj.js";
1
+ import { n as sendSessionCookies } from "../session-cookies-CfXdF1yd.js";
2
2
  import { n as resetAuth } from "../runtime-state-C0Rd1W4m.js";
3
- import { a as getAuthForDefinition, i as findVerifiedAuthUserId, n as createBetterAuthOptions } from "../auth-instance-5RSiFTDC.js";
3
+ import { a as getAuthForDefinition, i as findVerifiedAuthUserId, n as createBetterAuthOptions } from "../auth-instance-0PTsOttV.js";
4
4
  import { setAuthAccessIdentityResolver, setAuthRuntimeEnvResolver } from "../runtime/server.js";
5
- import { t as AbilityError } from "../ability-error-OKoyOwPM.js";
6
- import { C as toAuthRequest, D as withAuthorization, E as withAuth, S as signOut, T as withAnonymousAuthorization, _ as requireAbility, a as checkAuthMember, b as requireAuthorization, c as createAuthForRequest, d as getAuth, f as getAuthConsoleForRequest, g as listAuthEvents, h as handleAuthRequest, i as can, l as createAuthHandler, m as handleAuth, n as assertAuthOrigin, o as createAuth, p as getAuthEvents, r as authRoute, s as createAuthAccessHandler, t as aggregateAuthEvents, u as createAuthRequestRuntimeOptions, v as requireAuth, w as useAuth, x as requireCaller, y as requireAuthAccessRoutes } from "../server-iQNOXyfS.js";
7
- export { AbilityError, aggregateAuthEvents, assertAuthOrigin, can, checkAuthMember, createAuth, createAuthAccessHandler, createAuthForRequest, createAuthHandler, createAuthRequestRuntimeOptions, createBetterAuthOptions, authRoute as default, findVerifiedAuthUserId, getAuth, getAuthConsoleForRequest, getAuthEvents, getAuthForDefinition, handleAuth, handleAuthRequest, listAuthEvents, requireAbility, requireAuth, requireAuthAccessRoutes, requireAuthorization, requireCaller, resetAuth, sendSessionCookies, setAuthAccessIdentityResolver, setAuthRuntimeEnvResolver, signOut, toAuthRequest, useAuth, withAnonymousAuthorization, withAuth, withAuthorization };
5
+ import { t as AbilityError } from "../ability-error-Ccm5Iy4F.js";
6
+ import { C as signOut, D as withAuth, E as withAnonymousAuthorization, O as withAuthorization, S as requireCaller, T as useAuth, _ as listAuthEvents, a as can, b as requireAuthAccessRoutes, c as createAuthAccessHandler, d as createAuthRequestRuntimeOptions, f as getAuth, g as handleAuthRequest, h as handleAuth, i as authRoute, l as createAuthForRequest, m as getAuthEvents, n as assertAuthOrigin, o as checkAuthMember, p as getAuthConsoleForRequest, r as authMiddleware, s as createAuth, t as aggregateAuthEvents, u as createAuthHandler, v as requireAbility, w as toAuthRequest, x as requireAuthorization, y as requireAuth } from "../server-CZR2dVVp.js";
7
+ export { AbilityError, aggregateAuthEvents, assertAuthOrigin, authMiddleware, can, checkAuthMember, createAuth, createAuthAccessHandler, createAuthForRequest, createAuthHandler, createAuthRequestRuntimeOptions, createBetterAuthOptions, authRoute as default, findVerifiedAuthUserId, getAuth, getAuthConsoleForRequest, getAuthEvents, getAuthForDefinition, handleAuth, handleAuthRequest, listAuthEvents, requireAbility, requireAuth, requireAuthAccessRoutes, requireAuthorization, requireCaller, resetAuth, sendSessionCookies, setAuthAccessIdentityResolver, setAuthRuntimeEnvResolver, signOut, toAuthRequest, useAuth, withAnonymousAuthorization, withAuth, withAuthorization };
@@ -1,6 +1,14 @@
1
1
  import { t as isRecord } from "./object-CAK6UYR5.js";
2
+ import { t as clientRequest } from "./client-request-B1DCz3a9.js";
3
+ import { v as forwardedRequestOrigin } from "./auth-instance-0PTsOttV.js";
4
+ // src/client-request.ts
5
+ function clientRequestOrigin(request, trustProxyHeaders = false) {
6
+ const client = clientRequest(request);
7
+ return trustProxyHeaders ? forwardedRequestOrigin(client) : new URL(client.url).origin;
8
+ }
2
9
  // src/mcp-config.ts
3
10
  const mcpRegistrationPluginId = "vitehub-mcp-registration";
11
+ const mcpConsentClaim = "vitehub_consent_id";
4
12
  /**
5
13
  * The resources of MCP OAuth: the Better Auth `oauthProvider()` with `resources` and JWT access tokens of `jwt()`, from
6
14
  * `mcpOAuth()` or added by hand. Empty when the Auth has no MCP OAuth, also with `disableJwtPlugin`, whose access tokens
@@ -14,4 +22,4 @@ function mcpOAuthResources(plugins = []) {
14
22
  }
15
23
  /** True for a token in the JWS compact form (`header.payload.signature`), the form of an MCP OAuth access token. */
16
24
  const isJwsToken = (token) => /^[\w-]+\.[\w-]+\.[\w-]+$/.test(token);
17
- export { mcpOAuthResources as n, mcpRegistrationPluginId as r, isJwsToken as t };
25
+ export { clientRequestOrigin as a, mcpRegistrationPluginId as i, mcpConsentClaim as n, mcpOAuthResources as r, isJwsToken as t };
@@ -1,6 +1,6 @@
1
1
  import { Result, ResultError } from "@vite-hub/runtime";
2
2
  /** Why `verifyMcpRequest()` refused a token, in `error.data.reason` of `AUTH_MCP_TOKEN_INVALID`. */
3
- declare const mcpTokenInvalidReasons: readonly ["expired", "malformed", "wrong_resource", "no_keys", "sender_constrained", "user_gone", "not_allowed", "client_disabled", "session_ended"];
3
+ declare const mcpTokenInvalidReasons: readonly ["expired", "malformed", "wrong_resource", "no_keys", "sender_constrained", "user_gone", "not_allowed", "client_disabled", "grant_revoked", "session_ended"];
4
4
  type McpTokenInvalidReason = typeof mcpTokenInvalidReasons[number];
5
5
  /** `error.data` of `AUTH_MCP_TOKEN_INVALID`. `clientId` is set when the token's signature and claims are valid. */
6
6
  type McpTokenInvalidData = {
@@ -97,7 +97,9 @@ interface VerifyMcpRequestOptions {
97
97
  /**
98
98
  * Check the OAuth access token of an MCP request. The signing keys come from the Auth in-process, with no request to the
99
99
  * authorization server. The signature algorithm is pinned to the keys, and the issuer, the audience (the resource), and
100
- * the expiry are checked with 30 seconds of tolerance. The client must still be enabled and, when the token names a
100
+ * the expiry are checked with 30 seconds of tolerance. The client must still be enabled. Unless the client skips consent,
101
+ * the consent named by a `mcpOAuth()` token must still exist. Older tokens must be issued after the current consent.
102
+ * When the token names a
101
103
  * session, that session must still exist and be unexpired, unless the person granted `offline_access`: that grant is for
102
104
  * use while they are signed out, and Better Auth's refresh grant copies the session of the first sign-in into every
103
105
  * access token it mints. Sender-constrained tokens, including DPoP-bound tokens, are rejected even when presented as
@@ -1,7 +1,6 @@
1
- import { g as findAccessPolicyPlugin } from "./members-CRlYyxVk.js";
2
- import { t as authForRequest, u as trustsProxyHeaders } from "./auth-instance-5RSiFTDC.js";
3
- import { n as clientRequestOrigin } from "./client-request-BzMKtfCY.js";
4
- import { n as mcpOAuthResources } from "./mcp-config-C7srUMIZ.js";
1
+ import { g as findAccessPolicyPlugin } from "./members-USm08YwK.js";
2
+ import { t as authForRequest, u as trustsProxyHeaders } from "./auth-instance-0PTsOttV.js";
3
+ import { a as clientRequestOrigin, i as mcpRegistrationPluginId, n as mcpConsentClaim, r as mcpOAuthResources } from "./mcp-config-DYlTXmr6.js";
5
4
  import { t as isRecord } from "./object-CAK6UYR5.js";
6
5
  import { defineErrors } from "@vite-hub/runtime";
7
6
  import { verifyJwsAccessToken } from "better-auth/oauth2";
@@ -53,6 +52,7 @@ const mcpTokenInvalidReasons = [
53
52
  "user_gone",
54
53
  "not_allowed",
55
54
  "client_disabled",
55
+ "grant_revoked",
56
56
  "session_ended"
57
57
  ];
58
58
  const baseScopes = [
@@ -93,7 +93,9 @@ function banned(user) {
93
93
  /**
94
94
  * Check the OAuth access token of an MCP request. The signing keys come from the Auth in-process, with no request to the
95
95
  * authorization server. The signature algorithm is pinned to the keys, and the issuer, the audience (the resource), and
96
- * the expiry are checked with 30 seconds of tolerance. The client must still be enabled and, when the token names a
96
+ * the expiry are checked with 30 seconds of tolerance. The client must still be enabled. Unless the client skips consent,
97
+ * the consent named by a `mcpOAuth()` token must still exist. Older tokens must be issued after the current consent.
98
+ * When the token names a
97
99
  * session, that session must still exist and be unexpired, unless the person granted `offline_access`: that grant is for
98
100
  * use while they are signed out, and Better Auth's refresh grant copies the session of the first sign-in into every
99
101
  * access token it mints. Sender-constrained tokens, including DPoP-bound tokens, are rejected even when presented as
@@ -110,7 +112,6 @@ async function verifyMcpRequest(request, options = {}) {
110
112
  const origin = clientRequestOrigin(request, state.trustProxyHeaders);
111
113
  return await verifyToken(token, auth, state, options.resource ?? state.resources.find((entry) => new URL(entry).origin === origin && pathOf(entry) === url.pathname.replace(/\/+$/, "")), url.pathname);
112
114
  }
113
- /** The token of an `Authorization: Bearer` header. */
114
115
  const bearerToken = (headers) => /^Bearer\s+(\S+)$/i.exec(headers.get("authorization") ?? "")?.[1];
115
116
  /**
116
117
  * Check an MCP access token for `requireCaller()` on any route of the app. The token must name the `mcpOAuth()` resource
@@ -180,6 +181,27 @@ async function verifyToken(token, auth, state, resource, path) {
180
181
  }]
181
182
  }) : void 0;
182
183
  if (!clientId || !isRecord(client) || client.disabled) return refuse("client_disabled", "the OAuth client does not exist or is disabled.", clientId);
184
+ if (client.skipConsent !== true) {
185
+ const consentId = payload[mcpConsentClaim];
186
+ const where = [{
187
+ field: "clientId",
188
+ value: clientId
189
+ }, {
190
+ field: "userId",
191
+ value: user.id
192
+ }];
193
+ if (typeof consentId === "string") where.push({
194
+ field: "id",
195
+ value: consentId
196
+ });
197
+ const consent = consentId === null ? void 0 : await context.adapter.findOne({
198
+ model: "oauthConsent",
199
+ where
200
+ });
201
+ const grantedAt = isRecord(consent) && consent.createdAt instanceof Date ? Math.floor(consent.createdAt.getTime() / 1e3) : void 0;
202
+ const usesMcpOAuth = context.options.plugins?.some((plugin) => plugin.id === mcpRegistrationPluginId);
203
+ if (!(typeof consentId === "string" ? isRecord(consent) : consentId === void 0 && grantedAt !== void 0 && typeof payload.iat === "number" && (usesMcpOAuth ? payload.iat > grantedAt : payload.iat >= grantedAt))) return refuse("grant_revoked", "the person disconnected the client after it got the token, or has not granted it access.", clientId);
204
+ }
183
205
  const scope = payload.scope;
184
206
  const scopes = typeof scope === "string" ? scope.split(/\s+/).filter(Boolean) : Array.isArray(scope) ? scope.filter((entry) => typeof entry === "string") : [];
185
207
  if (typeof payload.sid === "string" && !scopes.includes("offline_access")) {
package/dist/mcp.d.ts CHANGED
@@ -1,12 +1,7 @@
1
- import { a as McpTokenInvalidData, c as VerifyMcpRequestError, d as deleteUnusedMcpClients, f as mcpTokenInvalidReasons, i as McpOAuthErrorCode, l as VerifyMcpRequestOptions, n as McpCaller, o as McpTokenInvalidError, p as verifyMcpRequest, r as McpOAuthAuth, s as McpTokenInvalidReason, t as DeleteUnusedMcpClientsOptions, u as VerifyMcpRequestResult } from "./mcp-token-DG1jmw4o.js";
1
+ import { a as McpTokenInvalidData, c as VerifyMcpRequestError, d as deleteUnusedMcpClients, f as mcpTokenInvalidReasons, i as McpOAuthErrorCode, l as VerifyMcpRequestOptions, n as McpCaller, o as McpTokenInvalidError, p as verifyMcpRequest, r as McpOAuthAuth, s as McpTokenInvalidReason, t as DeleteUnusedMcpClientsOptions, u as VerifyMcpRequestResult } from "./mcp-token-CxpopXmK.js";
2
2
  import { BetterAuthPlugin } from "better-auth";
3
3
  import { oauthProvider } from "@better-auth/oauth-provider";
4
4
  import { jwt } from "better-auth/plugins";
5
- /**
6
- * OAuth 2.1 sign-in for an MCP server of the app, with Better Auth as the authorization server. `mcpOAuth()` adds the
7
- * plugins, `serveMcpOAuthDiscovery()` answers the well-known documents at the origin root, `verifyMcpRequest()` checks the
8
- * access token of a request, and `deleteUnusedMcpClients()` removes registrations that never signed anyone in.
9
- */
10
5
  type OAuthProviderOptions = Parameters<typeof oauthProvider>[0];
11
6
  /** Options of {@link mcpOAuth}. */
12
7
  export interface McpOAuthOptions {
@@ -75,7 +70,7 @@ export interface McpOAuthDiscoveryOptions {
75
70
  * Every answer allows any origin with CORS, and an `OPTIONS` preflight gets `204`, so MCP clients in a browser read them.
76
71
  *
77
72
  * ```ts [server/middleware/mcp-oauth.ts]
78
- * import { defineHandler } from "h3"
73
+ * import { defineHandler } from "nitro/h3"
79
74
  * import { serveMcpOAuthDiscovery } from "vite-hub/auth/mcp"
80
75
  *
81
76
  * export default defineHandler(event => serveMcpOAuthDiscovery(event.req, { resourceName: "My app" }))
package/dist/mcp.js CHANGED
@@ -1,13 +1,11 @@
1
1
  import { t as isRecord } from "./object-CAK6UYR5.js";
2
- import { n as clientRequestOrigin } from "./client-request-BzMKtfCY.js";
3
- import { r as mcpRegistrationPluginId } from "./mcp-config-C7srUMIZ.js";
4
- import { c as verifyMcpRequest, i as mcpTokenInvalidReasons, n as baseScopes, o as pathOf, r as deleteUnusedMcpClients, s as stateOf, t as appAuth } from "./mcp-token-DgveSGEl.js";
2
+ import { a as clientRequestOrigin, i as mcpRegistrationPluginId, n as mcpConsentClaim } from "./mcp-config-DYlTXmr6.js";
3
+ import { c as verifyMcpRequest, i as mcpTokenInvalidReasons, n as baseScopes, o as pathOf, r as deleteUnusedMcpClients, s as stateOf, t as appAuth } from "./mcp-token-i-8NMulH.js";
5
4
  import { APIError, createAuthMiddleware } from "better-auth/api";
6
5
  import { oauthProvider, oauthProviderAuthServerMetadata, oauthProviderOpenIdConfigMetadata } from "@better-auth/oauth-provider";
7
6
  import { jwt } from "better-auth/plugins";
8
7
  // src/mcp.ts
9
8
  const registerPath = "/oauth2/register";
10
- /** Bounds RFC 7591 client metadata without restricting the private-use redirect schemes of native MCP clients. */
11
9
  function registrationProblem(body, maxBytes) {
12
10
  if (!isRecord(body)) return "Client metadata must be an object.";
13
11
  const redirects = body.redirect_uris;
@@ -29,7 +27,6 @@ function metadataError(status, description) {
29
27
  status
30
28
  });
31
29
  }
32
- /** Reads at most `maxBytes` of the body, so a large registration is refused before Better Auth parses it. */
33
30
  async function exceedsBytes(request, maxBytes) {
34
31
  const length = Number(request.headers.get("content-length"));
35
32
  if (Number.isFinite(length) && length > maxBytes) return true;
@@ -101,7 +98,29 @@ function mcpOAuth(options) {
101
98
  loginPage: options.loginPage,
102
99
  resources,
103
100
  scopes: [.../* @__PURE__ */ new Set([...baseScopes, ...options.scopes ?? []])],
104
- ...options.provider
101
+ ...options.provider,
102
+ extensions: [{ claims: { async accessToken({ client, ctx, referenceId, user }) {
103
+ if (!user || client.skipConsent) return {};
104
+ const findConsent = (reference) => ctx.context.adapter.findOne({
105
+ model: "oauthConsent",
106
+ where: [
107
+ {
108
+ field: "clientId",
109
+ value: client.clientId
110
+ },
111
+ {
112
+ field: "userId",
113
+ value: user.id
114
+ },
115
+ {
116
+ field: "referenceId",
117
+ value: reference
118
+ }
119
+ ]
120
+ });
121
+ const consent = referenceId ? await findConsent(referenceId) : await findConsent(null) ?? await findConsent("");
122
+ return { [mcpConsentClaim]: consent?.id ?? null };
123
+ } } }, ...options.provider?.extensions ?? []]
105
124
  }),
106
125
  registrationLimits(options)
107
126
  ];
@@ -128,7 +147,7 @@ const discoveryDocuments = [
128
147
  * Every answer allows any origin with CORS, and an `OPTIONS` preflight gets `204`, so MCP clients in a browser read them.
129
148
  *
130
149
  * ```ts [server/middleware/mcp-oauth.ts]
131
- * import { defineHandler } from "h3"
150
+ * import { defineHandler } from "nitro/h3"
132
151
  * import { serveMcpOAuthDiscovery } from "vite-hub/auth/mcp"
133
152
  *
134
153
  * export default defineHandler(event => serveMcpOAuthDiscovery(event.req, { resourceName: "My app" }))
@@ -1,9 +1,9 @@
1
- import { t as authErrorDiagnostics } from "./error-diagnostics-DkzL9ltR.js";
2
- import { t as authCloudflareEnv } from "./request-Dpq7GO8B.js";
3
- import { n as adminClaimVariable, t as adminClaimHash } from "./admin-claim-code-C3X_U43x.js";
1
+ import { t as authErrorDiagnostics } from "./error-diagnostics-BpQy1iIO.js";
2
+ import { t as authCloudflareEnv } from "./request-CdlcvqVc.js";
3
+ import { n as adminClaimVariable, t as adminClaimHash } from "./admin-claim-code-CMa0eRRm.js";
4
4
  import { t as invariant } from "./invariant-Dj2R1eMr.js";
5
5
  import { t as getAuthRuntimeState } from "./runtime-state-C0Rd1W4m.js";
6
- import { a as checkGitHubOrgMember } from "./events-BUaoHFoC.js";
6
+ import { a as checkGitHubOrgMember } from "./events-aP_Rz_gx.js";
7
7
  import { defineErrors, parseDuration } from "@vite-hub/runtime";
8
8
  import { APIError, createAuthEndpoint, createAuthMiddleware, getSessionFromCtx, sessionMiddleware } from "better-auth/api";
9
9
  import { createSessionStore, deleteSessionCookie, expireCookie, parseCookies } from "better-auth/cookies";
@@ -17,7 +17,6 @@ async function digest(value) {
17
17
  const bytes = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(value));
18
18
  return [...new Uint8Array(bytes)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
19
19
  }
20
- /** The request headers without the session cookies, so the endpoint and Better Auth's cookie cache see no session. */
21
20
  function withoutSessionCookies(headers, names) {
22
21
  const kept = [...parseCookies(headers.get("cookie") ?? "")].filter(([name]) => !names.some((prefix) => name === prefix || name.startsWith(`${prefix}.`)));
23
22
  const result = new Headers(headers);
@@ -452,7 +451,6 @@ function withMemberScopes(members, socialProviders) {
452
451
  function notMemberError() {
453
452
  return memberErrors.AUTH_NOT_MEMBER();
454
453
  }
455
- /** The answer that Auth sends for a refused sign-up or sign-in. */
456
454
  function notMember() {
457
455
  const error = notMemberError();
458
456
  return new APIError("FORBIDDEN", {
package/dist/nuxt.d.ts CHANGED
@@ -1,18 +1,6 @@
1
1
  /// <reference path="./host-declarations.d.ts" />
2
- import { Ct as AuthPageMeta, Tt as AuthPages, w as AuthOptions, wt as AuthPageMode } from "./types-BmRGse4l.js";
3
- import "vite";
4
- interface NuxtLayerDirectoryConfig {
5
- rootDir?: string;
6
- serverDir?: string;
7
- srcDir?: string;
8
- }
9
- /** The Nuxt options that locate the server directory of each layer. */
10
- interface NuxtServerDirOptions extends NuxtLayerDirectoryConfig {
11
- _layers?: ReadonlyArray<{
12
- config?: NuxtLayerDirectoryConfig;
13
- cwd?: string;
14
- }>;
15
- }
2
+ import { i as NuxtServerDirOptions, n as VITEHUB_SERVER_DIRS, r as resolveNuxtAuthDiscovery, t as VITEHUB_NUXT_AUTH_DISCOVERY } from "./vite-CZ_Z6IR3.js";
3
+ import { Et as AuthPages, Tt as AuthPageMode, w as AuthOptions, wt as AuthPageMeta } from "./types-DakualFJ.js";
16
4
  type VueImport = {
17
5
  as?: string;
18
6
  disabled?: boolean;
@@ -77,6 +65,8 @@ type NuxtLike = {
77
65
  srcDir?: string;
78
66
  ssr?: boolean;
79
67
  vite?: {
68
+ [VITEHUB_NUXT_AUTH_DISCOVERY]?: ReturnType<typeof resolveNuxtAuthDiscovery>;
69
+ [VITEHUB_SERVER_DIRS]?: string[];
80
70
  define?: Record<string, unknown>;
81
71
  plugins?: unknown[];
82
72
  root?: string;
package/dist/nuxt.js CHANGED
@@ -1,6 +1,6 @@
1
- import { _ as resolveViteHubProjectRoot, c as writeNuxtAuthDefinition, d as authAbilitiesCandidates, g as resolveNuxtServerDirs, h as methodOrder, l as resolveAuthViteConfig, m as createCachingRouteRuleFinder, o as createAuthNitroConfig, p as cachingRuleNames, s as hubAuth } from "./vite-GRzej8Cs.js";
2
- import { a as normalizePagePath, i as isUserPage, r as createAccessPageMatcher, t as accessPageBeats } from "./access-pages-Bej95blM.js";
3
- import { t as authErrorDiagnostics } from "./error-diagnostics-DkzL9ltR.js";
1
+ import { C as resolveViteHubProjectRoot, S as resolveNuxtServerDirs, _ as createCachingRouteRuleFinder, b as VITEHUB_SERVER_DIRS, c as createAuthNitroConfig, d as resolveAuthViteConfig, g as cachingRuleNames, l as hubAuth, o as authSchemaModule, p as authAbilitiesCandidates, s as authSchemaSpecifiers, u as writeNuxtAuthDefinition, v as methodOrder, x as resolveNuxtAuthDiscovery, y as VITEHUB_NUXT_AUTH_DISCOVERY } from "./vite-DVvWaN3D.js";
2
+ import { a as normalizePagePath, i as isUserPage, r as createAccessPageMatcher, t as accessPageBeats } from "./access-pages-lQGfRvfL.js";
3
+ import { t as authErrorDiagnostics } from "./error-diagnostics-BpQy1iIO.js";
4
4
  import { realpathSync } from "node:fs";
5
5
  import { dirname, isAbsolute, relative, resolve } from "node:path";
6
6
  import { fileURLToPath } from "node:url";
@@ -41,33 +41,21 @@ function addNuxtVueImports(nuxt, from, names) {
41
41
  for (const name of names) if (!fallbacks.has(name)) fallbacks.set(name, from);
42
42
  }
43
43
  // src/page-guard-cache.ts
44
- /**
45
- * Nuxt prerenders a page when it builds, without the cookie of a visitor. A guest page then renders for a signed-out
46
- * visitor, which is correct for every visitor until the browser reads the session: the page guard runs again in the
47
- * browser and sends a signed-in user away. A cache that renders the page for the first visitor can keep a redirect.
48
- */
49
44
  const guestCachingRuleNames = cachingRuleNames.filter((name) => name !== "prerender");
50
- /** A child page path is relative to the path of its parent. An empty child path is the parent path. */
51
45
  function joinPagePath(prefix, path) {
52
46
  if (path.startsWith("/")) return path;
53
47
  if (!path) return prefix;
54
48
  return `${prefix.replace(/\/$/, "")}/${path}`;
55
49
  }
56
- /** The page guard reads `'guest'` and `{ only: 'guest' }` as a guest page, and every other value as a user page. */
57
50
  function isGuestGuard(auth) {
58
51
  return auth === "guest" || typeof auth === "object" && auth !== null && Reflect.get(auth, "only") === "guest";
59
52
  }
60
53
  function isGuarded(auth) {
61
54
  return auth !== void 0 && auth !== false;
62
55
  }
63
- /** A static page path has no parameter, no regular expression, no repeat modifier, and no catch-all. */
64
56
  function isStaticPath(path) {
65
57
  return !/[\\:()*?+]/.test(path);
66
58
  }
67
- /**
68
- * Nuxt renders the payload of a page at `<page>/_payload.json`. A catch-all pattern already matches the payload paths
69
- * below it.
70
- */
71
59
  function payloadPattern(pattern) {
72
60
  if (/\/\*\*(?::\w+)?$/.test(pattern)) return void 0;
73
61
  return `${pattern.replace(/\/$/, "")}/_payload.json`;
@@ -75,28 +63,14 @@ function payloadPattern(pattern) {
75
63
  function parentPath(pattern) {
76
64
  return pattern.replace(/\/[^/]*$/, "") || "/";
77
65
  }
78
- /**
79
- * The page paths whose payloads a rou3 pattern matches. A last segment that matches one segment, such as `:file` or
80
- * `*`, also matches the payload of the parent path.
81
- */
82
66
  function payloadPages(pattern) {
83
67
  if (pattern.endsWith("/_payload.json")) return [parentPath(pattern)];
84
68
  if (/\/(?:\*|:\w+(?:\([^)]*\))?)$/.test(pattern)) return [pattern, parentPath(pattern)];
85
69
  return [pattern];
86
70
  }
87
- /**
88
- * Normalizes the literal text of a rou3 pattern as Nuxt does for route rules. Parameter names, constraints, and
89
- * escaped characters are not path text.
90
- */
91
71
  function normalizePattern(pattern, sensitive) {
92
72
  return pattern.replace(/\\.|:\w+(?:\([^)]*\))?|[^\\:]+/g, (token) => token[0] === "\\" || token[0] === ":" ? token : normalizePagePath(token, sensitive));
93
73
  }
94
- /**
95
- * The page and payload patterns of every page, with the `auth` that applies on them. Vue Router merges the meta of a
96
- * page into the meta of its child pages, so a child page without `auth` has the guard of its parent. A page with an
97
- * empty child path does not render its own path: Vue Router selects the empty child page there. A page path or alias
98
- * that rou3 cannot read exactly becomes a wider pattern, as Nuxt does for the route rules of `defineRouteRules()`.
99
- */
100
74
  function pageTargets(pages, toPatterns, prefixes = ["/"], inherited) {
101
75
  const targets = [];
102
76
  for (const page of pages) {
@@ -232,7 +206,6 @@ const composables = [
232
206
  "useAuthClient",
233
207
  "useUserSession"
234
208
  ];
235
- /** The components of `@vite-hub/auth/vue` that check the rules of `shared/abilities.ts`, by export name. */
236
209
  const abilityComponents = ["AuthPermission"];
237
210
  const nitroRegistered = /* @__PURE__ */ new WeakSet();
238
211
  const vueBridgeRegistered = /* @__PURE__ */ new WeakSet();
@@ -241,7 +214,6 @@ const componentsRegistered = /* @__PURE__ */ new WeakSet();
241
214
  const abilitiesWatchRegistered = /* @__PURE__ */ new WeakSet();
242
215
  const manifestRegistered = /* @__PURE__ */ new WeakSet();
243
216
  const pageCacheCheckRegistered = /* @__PURE__ */ new WeakSet();
244
- /** Better Auth's Vue client file, which `createAuthClient()` imports on first use. */
245
217
  function resolveBetterAuthVueClient() {
246
218
  try {
247
219
  return realpathSync(fileURLToPath(import.meta.resolve("better-auth/vue")));
@@ -249,13 +221,6 @@ function resolveBetterAuthVueClient() {
249
221
  return;
250
222
  }
251
223
  }
252
- /**
253
- * Attaches the page guard to the pages of `access.pages` with the `appMiddleware` route rule. Nuxt runs it on the server
254
- * render and on navigation in the browser. Nuxt merges the rules of all matching patterns and the most specific pattern
255
- * wins, so each rule sets every mode: `false` and a narrower other mode remove the mode of a wider pattern.
256
- * `assertAuthPages()` accepts only the patterns that keep this order. A `{ role }` value gets the middleware
257
- * `vitehub-auth-role-<i>`, where `i` is the index of its role in `pageRoles`.
258
- */
259
224
  function guardPages(routeRules, pages, pageRoles) {
260
225
  for (const [path, mode] of Object.entries(pages)) {
261
226
  const rule = routeRules[path] ??= {};
@@ -276,19 +241,10 @@ function pageRolesOf(pages) {
276
241
  for (const mode of Object.values(pages ?? {})) if (typeof mode === "object" && pageRoleIndex(roles, mode.role) < 0) roles.push(mode.role);
277
242
  return roles;
278
243
  }
279
- /** `appMiddleware` as a record. Nuxt reads a name or a list as `{ [name]: true }`. */
280
244
  function appMiddlewareRecord(value) {
281
245
  if (typeof value === "string" || Array.isArray(value)) return Object.fromEntries([value].flat().map((name) => [name, true]));
282
246
  return typeof value === "object" && value !== null ? value : void 0;
283
247
  }
284
- /**
285
- * Nuxt merges the `defineRouteRules()` of a page over the rule of each rou3 pattern of the page with `defu`. On the
286
- * pattern of an `access.pages` key, a name or a list then replaces the guard record, and a record merges with it. Other
287
- * patterns keep the value of the page, because `defu` joins two lists. A page with an optional parameter has several
288
- * patterns, and a record of the page would replace a name or a list of the app on the others, so they become records.
289
- * Keys match the rou3 patterns exactly: Nuxt turns the lists into records before it merges keys that differ only in a
290
- * parameter name, such as `/team/:id` and `/team/:_0`.
291
- */
292
248
  function expandPageMiddleware(pages, patternsOf, keys, routeRules, prefix = "") {
293
249
  for (const page of pages) {
294
250
  const middleware = page.rules?.appMiddleware;
@@ -319,6 +275,9 @@ function hubAuthNuxt(options = {}, nuxt) {
319
275
  ensureVueRuntimePlugin();
320
276
  nuxt.options.vite ??= {};
321
277
  nuxt.options.vite.plugins ??= [];
278
+ const nuxtDiscovery = resolveNuxtAuthDiscovery(nuxt.options);
279
+ nuxt.options.vite[VITEHUB_NUXT_AUTH_DISCOVERY] = nuxtDiscovery;
280
+ nuxt.options.vite[VITEHUB_SERVER_DIRS] ??= resolveNuxtServerDirs(nuxt.options);
322
281
  const vitePlugins = nuxt.options.vite.plugins.flat(Infinity);
323
282
  const viteRoot = nuxt.options.vite.root || nuxt.options.rootDir || process.cwd();
324
283
  const configuredEnvProjectRoot = resolve(viteRoot, options.env === false ? "." : options.env?.projectRoot || ".");
@@ -331,14 +290,16 @@ function hubAuthNuxt(options = {}, nuxt) {
331
290
  ...nuxt.options.vite.define,
332
291
  __VITEHUB_AUTH_APP_BASE_URL__: JSON.stringify(nuxt.options.app?.baseURL || "/")
333
292
  };
334
- const authPlugin = vitePlugins.find((plugin) => plugin?.name === "@vite-hub/auth/vite") || hubAuth(options.auth);
293
+ const authPlugin = vitePlugins.find((plugin) => plugin?.name === "@vite-hub/auth/vite") || hubAuth(options.auth, { layerAliases: nuxtDiscovery.layerAliases });
335
294
  if (!vitePlugins.some((plugin) => plugin?.name === "@vite-hub/auth/vite")) nuxt.options.vite.plugins.push(authPlugin);
336
295
  const resolveAuthOptions = () => options.auth;
337
296
  const resolveAuthConfig = () => {
338
- const configRoot = resolve(viteRoot);
339
- const serverDirs = resolveNuxtServerDirs(nuxt.options);
340
- const authOptions = resolveAuthOptions();
341
- return resolveAuthViteConfig(authOptions, configRoot, { serverDirs }) ?? resolveAuthViteConfig(authOptions, resolveViteHubProjectRoot(configRoot), { serverDirs });
297
+ const root = resolve(nuxt.options.rootDir || process.cwd());
298
+ return resolveAuthViteConfig(resolveAuthOptions(), resolve(root, viteRoot), {
299
+ projectRoot: resolveViteHubProjectRoot(root),
300
+ serverDirs: resolveNuxtServerDirs(nuxt.options),
301
+ layerAliases: nuxtDiscovery.layerAliases
302
+ });
342
303
  };
343
304
  if (options.nitro !== false && !nitroRegistered.has(nuxt)) {
344
305
  nitroRegistered.add(nuxt);
@@ -352,7 +313,8 @@ function hubAuthNuxt(options = {}, nuxt) {
352
313
  Object.assign(nitroConfig, createAuthNitroConfig(authPlugin, {
353
314
  nitro: nitroConfig,
354
315
  projectRoot: viteRoot,
355
- serverDirs: resolveNuxtServerDirs(nuxt.options)
316
+ serverDirs: resolveNuxtServerDirs(nuxt.options),
317
+ nuxtDiscovery
356
318
  }));
357
319
  });
358
320
  }
@@ -363,6 +325,20 @@ function hubAuthNuxt(options = {}, nuxt) {
363
325
  });
364
326
  }
365
327
  const authConfig = resolveAuthOptions() === false ? void 0 : resolveAuthConfig();
328
+ if (authConfig?.tables) {
329
+ const schemaAliases = Object.fromEntries(authSchemaSpecifiers.map((specifier) => [specifier, authSchemaModule(authConfig)]));
330
+ nuxt.options.alias = {
331
+ ...nuxt.options.alias,
332
+ ...schemaAliases
333
+ };
334
+ nuxt.options.nitro = {
335
+ ...nuxt.options.nitro,
336
+ alias: {
337
+ ...nuxt.options.nitro?.alias,
338
+ ...schemaAliases
339
+ }
340
+ };
341
+ }
366
342
  const signIn = authConfig?.access.signIn;
367
343
  const signInPage = signIn && "provider" in signIn ? null : signIn?.page ?? "/login";
368
344
  nuxt.options.runtimeConfig ??= {};
@@ -472,14 +448,6 @@ function hubAuthNuxt(options = {}, nuxt) {
472
448
  nuxt.options.nitro.plugins ??= [];
473
449
  if (!nuxt.options.nitro.plugins.includes(runtimePlugin)) nuxt.options.nitro.plugins.push(runtimePlugin);
474
450
  }
475
- /**
476
- * The Nuxt names of a component export under a prefix: the names that `<name>.vue` gets in a directory of
477
- * `components: [{ path, prefix }]`. As in Nuxt's `resolveComponentNameSegments()`, the prefix words that the name starts
478
- * with are dropped, so the prefix `MyAuth` gives `MyAuthPermission`.
479
- *
480
- * @example
481
- * componentNames("custom", "AuthPermission") // { kebabName: "custom-auth-permission", pascalName: "CustomAuthPermission" }
482
- */
483
451
  function componentNames(prefix, name) {
484
452
  const prefixWords = splitByCase(prefix).filter(Boolean);
485
453
  const nameWords = splitByCase(name);
@@ -1,4 +1,4 @@
1
- import { E as AuthRequestInput } from "./types-BmRGse4l.js";
1
+ import { E as AuthRequestInput } from "./types-DakualFJ.js";
2
2
  /**
3
3
  * The Nitro route `meta` of a handler that checks its own access, such as the ViteHub Console route. The access routes
4
4
  * leave a request to the handler that Nitro routed it to when that handler has this meta, whatever its path and method.
package/dist/presets.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as authErrorDiagnostics } from "./error-diagnostics-DkzL9ltR.js";
1
+ import { t as authErrorDiagnostics } from "./error-diagnostics-BpQy1iIO.js";
2
2
  import { parseDuration } from "@vite-hub/runtime";
3
3
  // src/presets.ts
4
4
  const defaultStatelessMaxAge = 604800;
@@ -17,7 +17,6 @@ function getActiveCloudflareEnv() {
17
17
  function isObjectLike(value) {
18
18
  return value !== null && (typeof value === "object" || typeof value === "function");
19
19
  }
20
- /** A Web Request, also from another realm. A request event has no string `url` and `method` of its own. */
21
20
  function isAuthRequest(input) {
22
21
  if (input instanceof Request) return true;
23
22
  if ("~standard" in input) return false;
@@ -1 +1,2 @@
1
- export default function authClientRequestPlugin(nitroApp: unknown): void;
1
+ /** Keeps each request that the Nitro app serves for `clientRequest()`. Auth and Comments each ship it, so it wraps `fetch` once. */
2
+ export default function clientRequestPlugin(nitroApp: unknown): void;
@@ -1,18 +1,21 @@
1
1
  import { t as isRecord } from "../object-CAK6UYR5.js";
2
- import { r as runWithClientRequest } from "../client-request-BzMKtfCY.js";
3
- // src/runtime/client-request-plugin.ts
2
+ import { n as runWithClientRequest } from "../client-request-B1DCz3a9.js";
3
+ // ../internal/src/runtime/client-request-plugin.ts
4
+ const installed = Symbol.for("vitehub.client-request.installed");
4
5
  function isRequest(value) {
5
6
  return isRecord(value) && typeof value.url === "string" && value.headers instanceof Headers;
6
7
  }
7
- function authClientRequestPlugin(nitroApp) {
8
+ /** Keeps each request that the Nitro app serves for `clientRequest()`. Auth and Comments each ship it, so it wraps `fetch` once. */
9
+ function clientRequestPlugin(nitroApp) {
8
10
  if (!isRecord(nitroApp)) return;
9
11
  const h3 = nitroApp.h3;
10
12
  const owner = isRecord(h3) && h3.fetch instanceof Function ? h3 : nitroApp;
11
13
  const fetch = owner.fetch;
12
- if (!(fetch instanceof Function)) return;
14
+ if (!(fetch instanceof Function) || owner[installed]) return;
15
+ owner[installed] = true;
13
16
  owner.fetch = (request, ...rest) => {
14
17
  const call = () => Reflect.apply(fetch, owner, [request, ...rest]);
15
18
  return isRequest(request) ? runWithClientRequest(request, call) : call();
16
19
  };
17
20
  }
18
- export { authClientRequestPlugin as default };
21
+ export { clientRequestPlugin as default };
@@ -1,3 +1,3 @@
1
1
  import "../server.js";
2
- import { j as authForRequest, r as aggregateAuthEvents, v as listAuthEvents } from "../server-1G_BbfBD.js";
2
+ import { M as authForRequest, r as aggregateAuthEvents, y as listAuthEvents } from "../server-4_EXgXFn.js";
3
3
  export { aggregateAuthEvents, authForRequest, listAuthEvents };
@@ -1,4 +1,4 @@
1
- import { g as listAuthEvents, t as aggregateAuthEvents } from "../server-iQNOXyfS.js";
2
- import { t as authForRequest } from "../auth-instance-5RSiFTDC.js";
1
+ import { _ as listAuthEvents, t as aggregateAuthEvents } from "../server-CZR2dVVp.js";
2
+ import { t as authForRequest } from "../auth-instance-0PTsOttV.js";
3
3
  import "../server.js";
4
4
  export { aggregateAuthEvents, authForRequest, listAuthEvents };
@@ -1,3 +1,3 @@
1
- import { s as AbilityRules } from "../abilities-CfvuGrBv.js";
1
+ import { s as AbilityRules } from "../abilities-6LE7VSdN.js";
2
2
  declare const abilities: AbilityRules;
3
3
  export { abilities as default };
@@ -1,4 +1,7 @@
1
+ import { r as AuthClientExtensionSource } from "../client-extension-BVBVUqa1.js";
1
2
  import { BetterAuthClientOptions } from "better-auth";
2
3
  /** The options of the default Auth client when the app has no `auth.client.ts`. */
3
4
  declare const options: BetterAuthClientOptions | undefined;
5
+ /** The parts of the client options, from the `auth.client.extend.ts` files. An app without parts exports none. */
6
+ export declare const extensions: readonly AuthClientExtensionSource[] | undefined;
4
7
  export { options as default };
@@ -1,4 +1,6 @@
1
1
  // src/runtime/empty-client.ts
2
2
  /** The options of the default Auth client when the app has no `auth.client.ts`. */
3
3
  const options = void 0;
4
- export { options as default };
4
+ /** The parts of the client options, from the `auth.client.extend.ts` files. An app without parts exports none. */
5
+ const extensions = void 0;
6
+ export { options as default, extensions };
@@ -1,4 +1,4 @@
1
- import { _ as AuthDefinition } from "../types-BmRGse4l.js";
1
+ import { _ as AuthDefinition } from "../types-DakualFJ.js";
2
2
  declare const definition: AuthDefinition | undefined;
3
3
  export declare function getAuthApp(): object | undefined;
4
4
  export { definition as default };
@@ -1,3 +1,4 @@
1
- import { t as authAccessHandlerMeta } from "../own-access-BvVUjaeL.js";
2
- import { a as setAuthAccessIdentityResolver, i as createLazyAuthAccessHandler, n as checkBuiltAuthPages, o as setAuthRuntimeEnvResolver, r as createAuthAccessRouteMatcher, t as AuthAccessRouteMatch } from "../server-B8kTFrHP.js";
3
- export { AuthAccessRouteMatch, authAccessHandlerMeta, checkBuiltAuthPages, createAuthAccessRouteMatcher, createLazyAuthAccessHandler, setAuthAccessIdentityResolver, setAuthRuntimeEnvResolver };
1
+ import { a as applyAuthExtensions } from "../extension-C2giF7w2.js";
2
+ import { t as authAccessHandlerMeta } from "../own-access-B7VRd92K.js";
3
+ import { a as setAuthAccessIdentityResolver, i as createLazyAuthAccessHandler, n as checkBuiltAuthPages, o as setAuthRuntimeEnvResolver, r as createAuthAccessRouteMatcher, t as AuthAccessRouteMatch } from "../server-DAIBBKbR.js";
4
+ export { AuthAccessRouteMatch, applyAuthExtensions, authAccessHandlerMeta, checkBuiltAuthPages, createAuthAccessRouteMatcher, createLazyAuthAccessHandler, setAuthAccessIdentityResolver, setAuthRuntimeEnvResolver };
@@ -1,8 +1,9 @@
1
- import { n as canonicalAccessPath, r as resolveAccessRoutePath } from "../application-path-zKi7NrvK.js";
2
- import { t as authErrorDiagnostics } from "../error-diagnostics-DkzL9ltR.js";
1
+ import { n as canonicalAccessPath, r as resolveAccessRoutePath } from "../application-path-LMc_ptL9.js";
2
+ import { t as authErrorDiagnostics } from "../error-diagnostics-BpQy1iIO.js";
3
3
  import { r as routedToAccessHandler, t as authAccessHandlerMeta } from "../own-access-CYsakJiH.js";
4
- import { r as unwrapAuthRequest } from "../request-Dpq7GO8B.js";
4
+ import { r as unwrapAuthRequest } from "../request-CdlcvqVc.js";
5
5
  import { t as getAuthRuntimeState } from "../runtime-state-C0Rd1W4m.js";
6
+ import { t as applyAuthExtensions } from "../extension-B35v_o1u.js";
6
7
  // src/runtime/server.ts
7
8
  function setAuthRuntimeEnvResolver(resolver, definition) {
8
9
  const state = getAuthRuntimeState();
@@ -84,4 +85,4 @@ function createLazyAuthAccessHandler(routes, load, publicRoutes = []) {
84
85
  return await (await handler)(input);
85
86
  };
86
87
  }
87
- export { authAccessHandlerMeta, checkBuiltAuthPages, createAuthAccessRouteMatcher, createLazyAuthAccessHandler, setAuthAccessIdentityResolver, setAuthRuntimeEnvResolver };
88
+ export { applyAuthExtensions, authAccessHandlerMeta, checkBuiltAuthPages, createAuthAccessRouteMatcher, createLazyAuthAccessHandler, setAuthAccessIdentityResolver, setAuthRuntimeEnvResolver };