@vite-hub/auth 0.5.1 → 0.6.1

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 (72) hide show
  1. package/README.md +2 -2
  2. package/dist/{abilities-3L1Y5Pnw.d.ts → abilities-BYOcyQ9B.d.ts} +1 -1
  3. package/dist/abilities.d.ts +1 -1
  4. package/dist/{ability-error-BHhPkrZd.js → ability-error-D3-u8k1A.js} +1 -1
  5. package/dist/{access-pages-BwImVHN_.js → access-pages-9aKr6z-k.js} +1 -1
  6. package/dist/agent.js +3 -3
  7. package/dist/{auth-instance-_J7R9Qs1.js → auth-instance-BWiRS9QZ.js} +73 -82
  8. package/dist/cli.js +1 -1
  9. package/dist/client-request-BzMKtfCY.js +52 -0
  10. package/dist/{console-runtime-vc3JQEuq.js → console-runtime-CaIXVtB_.js} +7 -206
  11. package/dist/console-runtime-DMH1I2fl.d.ts +32 -0
  12. package/dist/console-runtime.d.ts +3 -3
  13. package/dist/console-runtime.js +1 -1
  14. package/dist/{console-types-51lkf0lk.js → console-types-NrX5TWl3.js} +2 -1
  15. package/dist/console.d.ts +3 -3
  16. package/dist/console.js +1 -1
  17. package/dist/{database-options-DQ-8qYMl.js → database-options-B87hDU4j.js} +1 -1
  18. package/dist/{database-schema-options-CkSeU9V3.js → database-schema-options-peXHNLkJ.js} +1 -1
  19. package/dist/database.d.ts +2 -2
  20. package/dist/database.js +5 -5
  21. package/dist/{definition-MDGMNKrK.js → definition-BypPLIbI.js} +3 -3
  22. package/dist/{error-diagnostics-BssJr_2t.js → error-diagnostics-CUPwukgE.js} +1 -1
  23. package/dist/{events-DZqMiae_.js → events-BXU1_9mc.js} +2 -1
  24. package/dist/forward-sign-ins-BWXPPTRz.js +4 -0
  25. package/dist/forward.d.ts +24 -0
  26. package/dist/forward.js +42 -4
  27. package/dist/index.d.ts +2 -2
  28. package/dist/index.js +3 -3
  29. package/dist/internal/server.d.ts +2 -2
  30. package/dist/internal/server.js +4 -4
  31. package/dist/mcp-token-CmQbXbTu.d.ts +125 -0
  32. package/dist/{mcp-token--KuLYEub.js → mcp-token-CuqdbBy8.js} +45 -18
  33. package/dist/mcp.d.ts +2 -111
  34. package/dist/mcp.js +5 -3
  35. package/dist/{members-D3_Q5XJb.js → members-CwPIx10t.js} +3 -3
  36. package/dist/{nitro-kit-Bg4xUZAI.js → nitro-kit-BumWIKa5.js} +1 -1
  37. package/dist/nuxt.d.ts +1 -1
  38. package/dist/nuxt.js +3 -3
  39. package/dist/{own-access-C22hSIuF.d.ts → own-access-BNcxKrDl.d.ts} +1 -1
  40. package/dist/{own-access-DQgqxTbI.js → own-access-CYsakJiH.js} +1 -1
  41. package/dist/presets.js +1 -1
  42. package/dist/runtime/client-request-plugin.d.ts +1 -0
  43. package/dist/runtime/client-request-plugin.js +18 -0
  44. package/dist/runtime/console.d.ts +1 -1
  45. package/dist/runtime/console.js +2 -2
  46. package/dist/runtime/empty-abilities.d.ts +1 -1
  47. package/dist/runtime/empty-definition.d.ts +1 -1
  48. package/dist/runtime/server.d.ts +2 -2
  49. package/dist/runtime/server.js +3 -3
  50. package/dist/runtime-state-C0Rd1W4m.js +15 -0
  51. package/dist/schema.d.ts +1 -1
  52. package/dist/schema.js +1 -1
  53. package/dist/{server-DCsgxFPP.d.ts → server-BHniJi2m.d.ts} +2 -2
  54. package/dist/{server-CFWlYQJb.d.ts → server-C4Kni3Vj.d.ts} +13 -8
  55. package/dist/{server-D4Hi4TBI.js → server-Iru6jcnW.js} +13 -12
  56. package/dist/server.d.ts +3 -2
  57. package/dist/server.js +2 -2
  58. package/dist/{session-cookies-1FMcMnRh.js → session-cookies-fR6Pv4kD.js} +2 -2
  59. package/dist/{set-cookie-DkqM1kvj.js → set-cookie-DVfi-nJX.js} +1 -1
  60. package/dist/{table-specs-jw0jjU6l.js → table-specs-CCSY4tiS.js} +17 -14
  61. package/dist/{table-specs-BLm_Zlss.d.ts → table-specs-P4LvbOlX.d.ts} +28 -21
  62. package/dist/test.d.ts +1 -1
  63. package/dist/test.js +2 -2
  64. package/dist/{types-BHSgxyvV.d.ts → types-DmH31d2t.d.ts} +8 -21
  65. package/dist/{vite-D1xC9n1O.js → vite-CpWhT1Wi.js} +93 -27
  66. package/dist/vite.d.ts +1 -1
  67. package/dist/vite.js +1 -1
  68. package/dist/vue.d.ts +2 -2
  69. package/dist/vue.js +1 -1
  70. package/package.json +8 -8
  71. package/dist/console-runtime-BP1ZKJB0.d.ts +0 -71
  72. package/dist/runtime-state-DtKUfxKq.js +0 -24
@@ -1,9 +1,10 @@
1
- import { t as AuthConsole } from "./console-runtime-BP1ZKJB0.js";
2
- import { C as AuthGuardedHandler, E as AuthRequestInput, Ft as AuthEventPage, H as ResolvedAuthAccessRoute, Lt as AuthEventStore, N as AuthRuntimeOptions, Nt as AuthEventListInput, R as AuthSignInConfiguration, S as AuthFor, T as AuthRequest, V as RegisteredAuth, W as ViteHubAuth, _ as AuthDefinition, d as AuthAnonymousGuardedHandler, h as AuthBetterAuthRuntimeOptions, it as AuthConsoleHostOptions, jt as AuthEventAggregates, p as AuthAuthorization, u as AuthAnonymousAuthorize, zt as AuthEventWindow } from "./types-BHSgxyvV.js";
3
- import { i as AbilityName, n as AbilityAuthorization, t as AbilityArgs } from "./abilities-3L1Y5Pnw.js";
4
- import "./server-DCsgxFPP.js";
1
+ import { t as AuthConsole } from "./console-runtime-DMH1I2fl.js";
2
+ import { C as AuthGuardedHandler, E as AuthRequestInput, Ft as AuthEventStore, H as ResolvedAuthAccessRoute, Lt as AuthEventWindow, N as AuthRuntimeOptions, Nt as AuthEventPage, R as AuthSignInConfiguration, S as AuthFor, T as AuthRequest, V as RegisteredAuth, W as ViteHubAuth, _ as AuthDefinition, d as AuthAnonymousGuardedHandler, h as AuthBetterAuthRuntimeOptions, it as AuthConsoleHostOptions, jt as AuthEventListInput, kt as AuthEventAggregates, p as AuthAuthorization, u as AuthAnonymousAuthorize } from "./types-DmH31d2t.js";
3
+ import { i as AbilityName, n as AbilityAuthorization, t as AbilityArgs } from "./abilities-BYOcyQ9B.js";
4
+ import { o as McpTokenInvalidError } from "./mcp-token-CmQbXbTu.js";
5
+ import "./server-BHniJi2m.js";
5
6
  import "./ability-error-C1c30O6E.js";
6
- import { AccessAuthorizeOption, Result, ViteHubContext } from "@vite-hub/runtime";
7
+ import { AccessAuthorizeOption, Result, ResultError, ViteHubContext } from "@vite-hub/runtime";
7
8
  import { APIError } from "better-auth/api";
8
9
  import { AuthContext, BetterAuthOptions, BetterAuthPlugin, User } from "better-auth";
9
10
  /** Why `checkAuthMember()` did not let a user in. */
@@ -31,6 +32,10 @@ type AuthCaller<TRegistry = ViteHub.AuthRegistry> = {
31
32
  scopes: string[];
32
33
  };
33
34
  type AuthCallerErrorCode = "AUTH_MCP_TOKEN_INVALID" | "AUTH_SIGNED_OUT";
35
+ /** The error of `requireCaller()`. Check `code` to read the typed `data`, such as `data.reason` of `AUTH_MCP_TOKEN_INVALID`. */
36
+ type AuthCallerError = McpTokenInvalidError | ResultError<"AUTH_SIGNED_OUT", undefined>;
37
+ /** The `[error, caller]` tuple of `requireCaller()`. */
38
+ type AuthCallerResult<TRegistry = ViteHub.AuthRegistry> = [error: AuthCallerError, data: undefined] | [error: undefined, data: AuthCaller<TRegistry>];
34
39
  declare function findVerifiedAuthUserId(email: string, request: Request): Promise<string | undefined>;
35
40
  declare function createBetterAuthOptions(definition: AuthDefinition): AuthBetterAuthRuntimeOptions;
36
41
  declare function getAuthForDefinition<TDefinition extends AuthDefinition>(definition: TDefinition): AuthFor<TDefinition>;
@@ -147,8 +152,8 @@ declare function requireAuthorization<TInput extends AuthRequestInput>(event: TI
147
152
  * })
148
153
  * ```
149
154
  */
150
- declare function requireCaller(event: AuthRequestInput, definition?: undefined): Promise<Result<AuthCaller, AuthCallerErrorCode>>;
151
- declare function requireCaller(event: AuthRequestInput, definition: AuthDefinition | undefined): Promise<Result<AuthCaller<unknown>, AuthCallerErrorCode>>;
155
+ declare function requireCaller(event: AuthRequestInput, definition?: undefined): Promise<AuthCallerResult>;
156
+ declare function requireCaller(event: AuthRequestInput, definition: AuthDefinition | undefined): Promise<AuthCallerResult<unknown>>;
152
157
  /**
153
158
  * Checks a rule from `shared/abilities.ts` for the caller of a request. Returns the checked request, session, and user.
154
159
  * Throws an `AbilityError` when the rule refuses: `401` for a signed-out caller, else `403` or the status of `deny()`.
@@ -194,4 +199,4 @@ declare function aggregateAuthEvents(window: AuthEventWindow, definition?: AuthD
194
199
  * `host.impersonation` lets the Console start impersonation. It is off by default.
195
200
  */
196
201
  declare function getAuthConsoleForRequest(request: Request, event?: ViteHubContext, host?: AuthConsoleHostOptions): AuthConsole;
197
- export { authForRequest as A, requireCaller as C, withAnonymousAuthorization as D, useAuth as E, AuthCallerErrorCode as F, AuthCallerUser as I, AuthMemberErrorCode as L, findVerifiedAuthUserId as M, getAuthForDefinition as N, withAuth as O, AuthCaller as P, requireAuthorization as S, toAuthRequest as T, handleAuthRequest as _, authRoute as a, requireAuth as b, createAuth as c, createAuthHandler as d, createAuthRequestRuntimeOptions as f, handleAuth as g, getAuthEvents as h, assertAuthOrigin as i, createBetterAuthOptions as j, withAuthorization as k, createAuthAccessHandler as l, getAuthConsoleForRequest as m, AuthSignOutOptions as n, can as o, getAuth as p, aggregateAuthEvents as r, checkAuthMember as s, AuthEventReadErrorCode as t, createAuthForRequest as u, listAuthEvents as v, signOut as w, requireAuthAccessRoutes as x, requireAbility as y };
202
+ export { authForRequest as A, requireCaller as C, withAnonymousAuthorization as D, useAuth as E, AuthCallerError as F, AuthCallerErrorCode as I, AuthCallerResult as L, findVerifiedAuthUserId as M, getAuthForDefinition as N, withAuth as O, AuthCaller as P, AuthCallerUser as R, requireAuthorization as S, toAuthRequest as T, handleAuthRequest as _, authRoute as a, requireAuth as b, createAuth as c, createAuthHandler as d, createAuthRequestRuntimeOptions as f, handleAuth as g, getAuthEvents as h, assertAuthOrigin as i, createBetterAuthOptions as j, withAuthorization as k, createAuthAccessHandler as l, getAuthConsoleForRequest as m, AuthSignOutOptions as n, can as o, getAuth as p, aggregateAuthEvents as r, checkAuthMember as s, AuthEventReadErrorCode as t, createAuthForRequest as u, listAuthEvents as v, signOut as w, requireAuthAccessRoutes as x, requireAbility as y, AuthMemberErrorCode as z };
@@ -1,16 +1,17 @@
1
- import { t as createAuthConsole } from "./console-runtime-vc3JQEuq.js";
2
- import { _ as forwardedRequestOrigin, a as getAuthForDefinition, c as withSessionMarker, d as eventClientAddress, f as setRequestClientAddress, g as setAuthResponseOutcome, h as setAuthOutcome, l as resolveAuthOptions, m as runWithAuthEvent, n as createBetterAuthOptions, o as requestProvider, p as withClientAddress, r as envResolverFor, s as resolveDefaultDefinition, t as authForRequest, u as trustsProxyHeaders } from "./auth-instance-_J7R9Qs1.js";
1
+ import { t as createAuthConsole } from "./console-runtime-CaIXVtB_.js";
3
2
  import { i as resolveAuthMountPath, n as canonicalAccessPath } from "./application-path-zKi7NrvK.js";
4
- import { a as normalizeAuthBasePath } from "./access-pages-BwImVHN_.js";
3
+ import { a as normalizeAuthBasePath } from "./access-pages-9aKr6z-k.js";
5
4
  import { n as authRequestEvent, r as unwrapAuthRequest } from "./request-Dpq7GO8B.js";
6
- import { a as getAuthenticationSession, i as authenticationRefusalResponse, n as sendSessionCookies, r as authenticationRefusalError, t as prepareSessionCookies } from "./session-cookies-1FMcMnRh.js";
7
- import { n as getAuthRuntimeState } from "./runtime-state-DtKUfxKq.js";
8
- import { t as readSetCookies } from "./set-cookie-DkqM1kvj.js";
5
+ import { n as clientRequestOrigin } from "./client-request-BzMKtfCY.js";
6
+ import { a as getAuthForDefinition, c as withSessionMarker, d as eventClientAddress, f as setRequestClientAddress, g as setAuthResponseOutcome, h as setAuthOutcome, l as resolveAuthOptions, m as runWithAuthEvent, n as createBetterAuthOptions, o as requestProvider, p as withClientAddress, r as envResolverFor, s as resolveDefaultDefinition, t as authForRequest, u as trustsProxyHeaders } from "./auth-instance-BWiRS9QZ.js";
7
+ import { a as getAuthenticationSession, i as authenticationRefusalResponse, n as sendSessionCookies, r as authenticationRefusalError, t as prepareSessionCookies } from "./session-cookies-fR6Pv4kD.js";
8
+ import { t as getAuthRuntimeState } from "./runtime-state-C0Rd1W4m.js";
9
+ import { t as readSetCookies } from "./set-cookie-DVfi-nJX.js";
9
10
  import { createAuthAccessRouteMatcher } from "./runtime/server.js";
10
- import { n as checkAbility, t as AbilityError } from "./ability-error-BHhPkrZd.js";
11
- import { i as parseAuthEventWindow, r as parseAuthEventList } from "./events-DZqMiae_.js";
12
- import { t as authErrorDiagnostics } from "./error-diagnostics-BssJr_2t.js";
13
- import { i as notMemberError, l as findAccessPolicyPlugin } from "./members-D3_Q5XJb.js";
11
+ import { n as checkAbility, t as AbilityError } from "./ability-error-D3-u8k1A.js";
12
+ import { i as parseAuthEventWindow, r as parseAuthEventList } from "./events-BXU1_9mc.js";
13
+ import { t as authErrorDiagnostics } from "./error-diagnostics-CUPwukgE.js";
14
+ import { i as notMemberError, l as findAccessPolicyPlugin } from "./members-CwPIx10t.js";
14
15
  import { n as mcpOAuthResources, t as isJwsToken } from "./mcp-config-C7srUMIZ.js";
15
16
  import { defineErrors, toResultError } from "@vite-hub/runtime";
16
17
  import { HTTPError } from "nitro/h3";
@@ -847,9 +848,9 @@ async function readCaller(event, definition) {
847
848
  const auth = authForRequest(request, authRequestEvent(event), definition);
848
849
  const { options } = await auth.$context;
849
850
  if (isJwsToken(token) && mcpOAuthResources(options.plugins).length) {
850
- const { verifyAppAccessToken } = await import("./mcp-token--KuLYEub.js").then((n) => n.i);
851
+ const { verifyAppAccessToken } = await import("./mcp-token-CuqdbBy8.js").then((n) => n.a);
851
852
  const url = new URL(request.url);
852
- const [error, caller] = await verifyAppAccessToken(token, trustsProxyHeaders(options) ? forwardedRequestOrigin(request) : url.origin, url.pathname, auth);
853
+ const [error, caller] = await verifyAppAccessToken(token, clientRequestOrigin(request, trustsProxyHeaders(options)), url.pathname, auth);
853
854
  if (error) return [error, void 0];
854
855
  return [void 0, Object.freeze({
855
856
  client: {
package/dist/server.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  /// <reference path="./host-declarations.d.ts" />
2
- import { C as requireCaller, D as withAnonymousAuthorization, E as useAuth, F as AuthCallerErrorCode, I as AuthCallerUser, L as AuthMemberErrorCode, O as withAuth, P as AuthCaller, S as requireAuthorization, a as authRoute, b as requireAuth, d as createAuthHandler, g as handleAuth, h as getAuthEvents, k as withAuthorization, m as getAuthConsoleForRequest, o as can, r as aggregateAuthEvents, s as checkAuthMember, t as AuthEventReadErrorCode, v as listAuthEvents, w as signOut, y as requireAbility } from "./server-CFWlYQJb.js";
2
+ import { C as requireCaller, D as withAnonymousAuthorization, E as useAuth, F as AuthCallerError, I as AuthCallerErrorCode, L as AuthCallerResult, O as withAuth, P as AuthCaller, R as AuthCallerUser, S as requireAuthorization, a as authRoute, b as requireAuth, d as createAuthHandler, g as handleAuth, h as getAuthEvents, k as withAuthorization, m as getAuthConsoleForRequest, o as can, r as aggregateAuthEvents, s as checkAuthMember, t as AuthEventReadErrorCode, v as listAuthEvents, w as signOut, y as requireAbility, z as AuthMemberErrorCode } from "./server-C4Kni3Vj.js";
3
+ import { a as McpTokenInvalidData, o as McpTokenInvalidError, s as McpTokenInvalidReason } from "./mcp-token-CmQbXbTu.js";
3
4
  import { n as AbilityErrorData, t as AbilityError } from "./ability-error-C1c30O6E.js";
4
- export { AbilityError, type AbilityErrorData, type AuthCaller, type AuthCallerErrorCode, type AuthCallerUser, type AuthEventReadErrorCode, type AuthMemberErrorCode, aggregateAuthEvents, can, checkAuthMember, createAuthHandler, authRoute as default, getAuthConsoleForRequest, getAuthEvents, handleAuth, listAuthEvents, requireAbility, requireAuth, requireAuthorization, requireCaller, signOut, useAuth, withAnonymousAuthorization, withAuth, withAuthorization };
5
+ export { AbilityError, type AbilityErrorData, type AuthCaller, type AuthCallerError, type AuthCallerErrorCode, type AuthCallerResult, type AuthCallerUser, type AuthEventReadErrorCode, type AuthMemberErrorCode, type McpTokenInvalidData, type McpTokenInvalidError, type McpTokenInvalidReason, aggregateAuthEvents, can, checkAuthMember, createAuthHandler, authRoute as default, getAuthConsoleForRequest, getAuthEvents, handleAuth, listAuthEvents, requireAbility, requireAuth, requireAuthorization, requireCaller, signOut, useAuth, withAnonymousAuthorization, withAuth, withAuthorization };
package/dist/server.js CHANGED
@@ -1,3 +1,3 @@
1
- import { t as AbilityError } from "./ability-error-BHhPkrZd.js";
2
- import { D as withAuthorization, E as withAuth, S as signOut, T as withAnonymousAuthorization, _ as requireAbility, a as checkAuthMember, b as requireAuthorization, f as getAuthConsoleForRequest, g as listAuthEvents, i as can, l as createAuthHandler, m as handleAuth, p as getAuthEvents, r as authRoute, t as aggregateAuthEvents, v as requireAuth, w as useAuth, x as requireCaller } from "./server-D4Hi4TBI.js";
1
+ import { t as AbilityError } from "./ability-error-D3-u8k1A.js";
2
+ import { D as withAuthorization, E as withAuth, S as signOut, T as withAnonymousAuthorization, _ as requireAbility, a as checkAuthMember, b as requireAuthorization, f as getAuthConsoleForRequest, g as listAuthEvents, i as can, l as createAuthHandler, m as handleAuth, p as getAuthEvents, r as authRoute, t as aggregateAuthEvents, v as requireAuth, w as useAuth, x as requireCaller } from "./server-Iru6jcnW.js";
3
3
  export { AbilityError, aggregateAuthEvents, can, checkAuthMember, createAuthHandler, authRoute as default, getAuthConsoleForRequest, getAuthEvents, handleAuth, listAuthEvents, requireAbility, requireAuth, requireAuthorization, requireCaller, signOut, useAuth, withAnonymousAuthorization, withAuth, withAuthorization };
@@ -1,5 +1,5 @@
1
- import { t as authErrorDiagnostics } from "./error-diagnostics-BssJr_2t.js";
2
- import { r as throwAuthenticationProviderError, t as readSetCookies } from "./set-cookie-DkqM1kvj.js";
1
+ import { t as authErrorDiagnostics } from "./error-diagnostics-CUPwukgE.js";
2
+ import { r as throwAuthenticationProviderError, t as readSetCookies } from "./set-cookie-DVfi-nJX.js";
3
3
  import { t as isRecord } from "./object-CAK6UYR5.js";
4
4
  import { n as authRequestEvent } from "./request-Dpq7GO8B.js";
5
5
  import { HTTPError } from "nitro/h3";
@@ -1,4 +1,4 @@
1
- import { t as authErrorDiagnostics } from "./error-diagnostics-BssJr_2t.js";
1
+ import { t as authErrorDiagnostics } from "./error-diagnostics-CUPwukgE.js";
2
2
  import { ViteHubError, isViteHubError } from "@vite-hub/runtime";
3
3
  // src/errors.ts
4
4
  function invalidAuthenticationErrorOptions() {
@@ -1,9 +1,8 @@
1
- import { t as authErrorDiagnostics } from "./error-diagnostics-BssJr_2t.js";
1
+ import { t as authErrorDiagnostics } from "./error-diagnostics-CUPwukgE.js";
2
2
  /**
3
- * The Better Auth core tables, with the fields of the plugins that ViteHub ships: `admin()` (`user.role`, bans, and
4
- * `session.impersonatedBy`), the `jwt()` and `oauthProvider()` tables of `mcpOAuth()`, the tables of
5
- * `organization()` and of `passkey()` from `@better-auth/passkey`, and the table of Better Auth's limiter. A test checks this
6
- * list against Better Auth's own `getAuthTables()`, so a Better Auth upgrade that changes a table fails it.
3
+ * The Better Auth core tables, with the tables of the plugins that ViteHub ships: `jwt()` and `oauthProvider()` of
4
+ * `mcpOAuth()`, `organization()`, `passkey()` from `@better-auth/passkey`, and the table of Better Auth's limiter. The
5
+ * fields of `admin()` are in `authPluginSchemas`. A test checks this list against Better Auth's own `getAuthTables()`, so a Better Auth upgrade that changes a table fails it.
7
6
  */
8
7
  const authTableSpecs = {
9
8
  user: { fields: {
@@ -32,14 +31,7 @@ const authTableSpecs = {
32
31
  required: true,
33
32
  defaultValue: "now",
34
33
  onUpdate: true
35
- },
36
- role: { type: "string" },
37
- banned: {
38
- type: "boolean",
39
- defaultValue: false
40
- },
41
- banReason: { type: "string" },
42
- banExpires: { type: "date" }
34
+ }
43
35
  } },
44
36
  session: { fields: {
45
37
  expiresAt: {
@@ -73,7 +65,6 @@ const authTableSpecs = {
73
65
  onDelete: "cascade"
74
66
  }
75
67
  },
76
- impersonatedBy: { type: "string" },
77
68
  activeOrganizationId: { type: "string" }
78
69
  } },
79
70
  account: { fields: {
@@ -575,6 +566,18 @@ const authTableSpecs = {
575
566
  * `getAuthTables()`. `apiKey()` and `stripe()` are copied from `@better-auth/api-key` and `@better-auth/stripe` 1.7.
576
567
  */
577
568
  const authPluginSchemas = {
569
+ admin: { fields: {
570
+ user: {
571
+ role: { type: "string" },
572
+ banned: {
573
+ type: "boolean",
574
+ defaultValue: false
575
+ },
576
+ banReason: { type: "string" },
577
+ banExpires: { type: "date" }
578
+ },
579
+ session: { impersonatedBy: { type: "string" } }
580
+ } },
578
581
  anonymous: { fields: { user: { isAnonymous: {
579
582
  type: "boolean",
580
583
  defaultValue: false
@@ -57,19 +57,6 @@ declare const coreTableSpecs: {
57
57
  readonly defaultValue: "now";
58
58
  readonly onUpdate: true;
59
59
  };
60
- readonly role: {
61
- readonly type: "string";
62
- };
63
- readonly banned: {
64
- readonly type: "boolean";
65
- readonly defaultValue: false;
66
- };
67
- readonly banReason: {
68
- readonly type: "string";
69
- };
70
- readonly banExpires: {
71
- readonly type: "date";
72
- };
73
60
  };
74
61
  };
75
62
  readonly session: {
@@ -109,9 +96,6 @@ declare const coreTableSpecs: {
109
96
  readonly onDelete: "cascade";
110
97
  };
111
98
  };
112
- readonly impersonatedBy: {
113
- readonly type: "string";
114
- };
115
99
  readonly activeOrganizationId: {
116
100
  readonly type: "string";
117
101
  };
@@ -803,14 +787,13 @@ declare const coreTableSpecs: {
803
787
  /** The literal type of `authTableSpecs`, which types the columns of the Auth tables. */
804
788
  type AuthCoreTableSpecs = typeof coreTableSpecs;
805
789
  /**
806
- * The Better Auth core tables, with the fields of the plugins that ViteHub ships: `admin()` (`user.role`, bans, and
807
- * `session.impersonatedBy`), the `jwt()` and `oauthProvider()` tables of `mcpOAuth()`, the tables of
808
- * `organization()` and of `passkey()` from `@better-auth/passkey`, and the table of Better Auth's limiter. A test checks this
809
- * list against Better Auth's own `getAuthTables()`, so a Better Auth upgrade that changes a table fails it.
790
+ * The Better Auth core tables, with the tables of the plugins that ViteHub ships: `jwt()` and `oauthProvider()` of
791
+ * `mcpOAuth()`, `organization()`, `passkey()` from `@better-auth/passkey`, and the table of Better Auth's limiter. The
792
+ * fields of `admin()` are in `authPluginSchemas`. A test checks this list against Better Auth's own `getAuthTables()`, so a Better Auth upgrade that changes a table fails it.
810
793
  */
811
794
  declare const authTableSpecs: Readonly<Record<AuthTableName, AuthTableSpec>>;
812
795
  /** The Better Auth plugins whose tables and columns `authDatabase()` adds when the Auth Definition imports them. */
813
- type AuthSchemaPlugin = "anonymous" | "apiKey" | "lastLoginMethod" | "phoneNumber" | "stripe" | "twoFactor" | "username";
796
+ type AuthSchemaPlugin = "admin" | "anonymous" | "apiKey" | "lastLoginMethod" | "phoneNumber" | "stripe" | "twoFactor" | "username";
814
797
  /** The core Better Auth models. Each one takes `additionalFields`. */
815
798
  type AuthCoreModel = "user" | "session" | "account" | "verification";
816
799
  interface AuthPluginSchema {
@@ -820,6 +803,30 @@ interface AuthPluginSchema {
820
803
  tables?: Readonly<Record<string, AuthTableSpec>>;
821
804
  }
822
805
  declare const pluginSchemas: {
806
+ readonly admin: {
807
+ readonly fields: {
808
+ readonly user: {
809
+ readonly role: {
810
+ readonly type: "string";
811
+ };
812
+ readonly banned: {
813
+ readonly type: "boolean";
814
+ readonly defaultValue: false;
815
+ };
816
+ readonly banReason: {
817
+ readonly type: "string";
818
+ };
819
+ readonly banExpires: {
820
+ readonly type: "date";
821
+ };
822
+ };
823
+ readonly session: {
824
+ readonly impersonatedBy: {
825
+ readonly type: "string";
826
+ };
827
+ };
828
+ };
829
+ };
823
830
  readonly anonymous: {
824
831
  readonly fields: {
825
832
  readonly user: {
package/dist/test.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { _ as AuthDefinition } from "./types-BHSgxyvV.js";
1
+ import { _ as AuthDefinition } from "./types-DmH31d2t.js";
2
2
  import { Session, User } from "better-auth";
3
3
  /** The user to sign in. Auth creates it when no user has this email. Other fields, such as `role`, go to the new user. */
4
4
  export interface SignInTestUser {
package/dist/test.js CHANGED
@@ -1,5 +1,5 @@
1
- import { s as resolveDefaultDefinition, t as authForRequest } from "./auth-instance-_J7R9Qs1.js";
2
- import { t as authErrorDiagnostics } from "./error-diagnostics-BssJr_2t.js";
1
+ import { s as resolveDefaultDefinition, t as authForRequest } from "./auth-instance-BWiRS9QZ.js";
2
+ import { t as authErrorDiagnostics } from "./error-diagnostics-CUPwukgE.js";
3
3
  import { testUtils } from "better-auth/plugins";
4
4
  // src/test.ts
5
5
  /**
@@ -1,10 +1,10 @@
1
1
  import { t as AuthPreset } from "./presets-C6AtiRdI.js";
2
- import { i as AuthSchemaOptions } from "./table-specs-BLm_Zlss.js";
2
+ import { i as AuthSchemaOptions } from "./table-specs-P4LvbOlX.js";
3
3
  import { AccessAuthorizationContext, AccessAuthorize, AccessAuthorizeResult, AnonymousAccessAuthorizationContext, AnonymousAccessAuthorize, Duration } from "@vite-hub/runtime";
4
4
  import { ViteHubContext as ViteHubContext$1 } from "@vite-hub/runtime/internal/h3";
5
5
  import { Auth, BetterAuthOptions, DBAdapter, Session, User } from "better-auth";
6
6
  import { EnvDatabase } from "@vite-hub/env/database";
7
- declare const authEventTypes: readonly ["user.signed_up", "user.signed_in", "user.signed_out", "sign_in.failed", "session.revoked", "user.banned", "user.unbanned", "user.role_changed", "user.updated", "user.removed", "impersonation.started", "impersonation.stopped", "oauth.consent_granted", "oauth.consent_revoked", "organization.member_added", "organization.member_removed", "organization.member_role_changed"];
7
+ declare const authEventTypes: readonly ["user.signed_up", "user.signed_in", "user.signed_out", "sign_in.failed", "session.revoked", "session.expired", "user.banned", "user.unbanned", "user.role_changed", "user.updated", "user.removed", "impersonation.started", "impersonation.stopped", "oauth.consent_granted", "oauth.consent_revoked", "organization.member_added", "organization.member_removed", "organization.member_role_changed"];
8
8
  type AuthEventType = typeof authEventTypes[number];
9
9
  type AuthEventActor = "system" | `user:${string}`;
10
10
  type AuthDevice = "desktop" | "mobile" | "tablet" | "bot" | "unknown";
@@ -277,24 +277,6 @@ interface AuthConsoleSession {
277
277
  updatedAt: string;
278
278
  }
279
279
  /** A user that a host signs in without a password, such as a Console member or an invited guest. */
280
- interface AuthConsoleHostUserInput {
281
- /** The email of an existing person. Without it, the user is new and gets a placeholder email. */
282
- email?: string;
283
- name: string;
284
- image?: string;
285
- /** Roles to add to the comma-separated `user.role` of `admin()`. */
286
- roles: readonly string[];
287
- /**
288
- * Roles that the host owns. An existing user loses those of them that `roles` does not name, so a host can take a
289
- * role back. Other roles of the user stay.
290
- */
291
- owned?: readonly string[];
292
- }
293
- /** A live session of a user that holds a host role, with the user's roles. */
294
- interface AuthConsoleHostSession extends AuthConsoleSession {
295
- roles: string[];
296
- guest: boolean;
297
- }
298
280
  interface AuthConsoleAgent {
299
281
  id: string;
300
282
  clientId: string;
@@ -419,7 +401,12 @@ type AuthSessionOptions = NonNullable<BetterAuthOptions["session"]> & {
419
401
  interface AuthRuntimeEnv extends ViteHub.AuthRuntimeEnv {}
420
402
  interface AuthRuntimeContext<TEnv extends Record<string, unknown> = AuthRuntimeEnv> {
421
403
  env: TEnv;
404
+ /**
405
+ * The request that Auth serves. A request that the server sends to itself during server rendering has the URL
406
+ * `http://localhost/...`, so read the origin from `requestOrigin`.
407
+ */
422
408
  request?: Pick<Request, "headers" | "url">;
409
+ /** The origin of the request that the client sent, or `http://localhost` outside a request. */
423
410
  requestOrigin: string;
424
411
  }
425
412
  type AuthRuntimeOptions = Partial<Omit<BetterAuthOptions, "basePath" | "database">> & {
@@ -624,4 +611,4 @@ type RegisteredAuth<TRegistry = ViteHub.AuthRegistry> = TRegistry extends {
624
611
  } ? AuthFor<TDefinition> : ViteHubAuth;
625
612
  /** `false` turns Auth off. `server/auth.ts` turns it on, and `defineAuth()` holds every Auth option. */
626
613
  type AuthOptions = false;
627
- export { AuthConsoleEventGroup as $, AuthRuntimeEnv as A, AuthEventActor as At, DiscoveredAuthDefinition as B, AuthEventsConfiguration as Bt, AuthGuardedHandler as C, authConsoleActionNames as Ct, AuthReservedOption as D, AuthPages as Dt, AuthRequestInput as E, AuthPageMode as Et, AuthSessionRefresh as F, AuthEventPage as Ft, AuthConsoleAction as G, ResolvedAuthAccessRoute as H, defaultAuthEventRetention as Ht, AuthSessionRefreshContext as I, AuthEventRetention as It, AuthConsoleAgent as J, AuthConsoleActivity as K, AuthSessionRefreshFields as L, AuthEventStore as Lt, AuthRuntimeOption as M, AuthEventCounts as Mt, AuthRuntimeOptions as N, AuthEventListInput as Nt, AuthResolvedDefinitionOptions as O, AuthDevice as Ot, AuthSessionOptions as P, AuthEventMetadata as Pt, AuthConsoleEvent as Q, AuthSignInConfiguration as R, AuthEventType as Rt, AuthFor as S, AuthConsoleValue as St, AuthRequest as T, AuthPageMeta as Tt, ResolvedAuthViteConfig as U, RegisteredAuth as V, createDatabaseAuthEventStore as Vt, ViteHubAuth as W, AuthConsoleColumn as X, AuthConsoleCapability as Y, AuthConsoleDescription as Z, AuthDefinition as _, AuthConsoleRoles as _t, AuthAccessPolicy as a, AuthConsoleHostSession as at, AuthDefinitionResolver as b, AuthConsoleUser as bt, AuthAccessRouteConfiguration as c, AuthConsoleList as ct, AuthAnonymousGuardedHandler as d, AuthConsoleOrganization as dt, AuthConsoleEventUser as et, AuthAppDatabase as f, AuthConsoleOrganizationDetail as ft, AuthComponentsOptions as g, AuthConsoleQuery as gt, AuthBetterAuthRuntimeOptions as h, AuthConsolePolicy as ht, AuthAccessConfiguration as i, AuthConsoleHostOptions as it, AuthRuntimeOnlyOptions as j, AuthEventAggregates as jt, AuthRuntimeContext as k, AuthEvent as kt, AuthAnonymousAuthorization as l, AuthConsoleMutation as lt, AuthBetterAuthOptions as m, AuthConsolePage as mt, AuthAccessAuthorize as n, AuthConsoleFieldPolicy as nt, AuthAccessPolicyContext as o, AuthConsoleHostUserInput as ot, AuthAuthorization as p, AuthConsoleOverview as pt, AuthConsoleActivityQuery as q, AuthAccessAuthorizeResult as r, AuthConsoleFieldType as rt, AuthAccessRoute as s, AuthConsoleImpersonation as st, AuthAccessAuthorizationContext as t, AuthConsoleField as tt, AuthAnonymousAuthorize as u, AuthConsoleOptions as ut, AuthDefinitionInput as v, AuthConsoleSession as vt, AuthOptions as w, authConsoleEventGroups as wt, AuthDeleteAccountOptions as x, AuthConsoleUserDetail as xt, AuthDefinitionOptions as y, AuthConsoleSessionUser as yt, AuthViteHubOptions as z, AuthEventWindow as zt };
614
+ export { AuthConsoleEventGroup as $, AuthRuntimeEnv as A, AuthEventCounts as At, DiscoveredAuthDefinition as B, defaultAuthEventRetention as Bt, AuthGuardedHandler as C, AuthPageMeta as Ct, AuthReservedOption as D, AuthEvent as Dt, AuthRequestInput as E, AuthDevice as Et, AuthSessionRefresh as F, AuthEventStore as Ft, AuthConsoleAction as G, ResolvedAuthAccessRoute as H, AuthSessionRefreshContext as I, AuthEventType as It, AuthConsoleAgent as J, AuthConsoleActivity as K, AuthSessionRefreshFields as L, AuthEventWindow as Lt, AuthRuntimeOption as M, AuthEventMetadata as Mt, AuthRuntimeOptions as N, AuthEventPage as Nt, AuthResolvedDefinitionOptions as O, AuthEventActor as Ot, AuthSessionOptions as P, AuthEventRetention as Pt, AuthConsoleEvent as Q, AuthSignInConfiguration as R, AuthEventsConfiguration as Rt, AuthFor as S, authConsoleEventGroups as St, AuthRequest as T, AuthPages as Tt, ResolvedAuthViteConfig as U, RegisteredAuth as V, ViteHubAuth as W, AuthConsoleColumn as X, AuthConsoleCapability as Y, AuthConsoleDescription as Z, AuthDefinition as _, AuthConsoleSessionUser as _t, AuthAccessPolicy as a, AuthConsoleImpersonation as at, AuthDefinitionResolver as b, AuthConsoleValue as bt, AuthAccessRouteConfiguration as c, AuthConsoleOptions as ct, AuthAnonymousGuardedHandler as d, AuthConsoleOverview as dt, AuthConsoleEventUser as et, AuthAppDatabase as f, AuthConsolePage as ft, AuthComponentsOptions as g, AuthConsoleSession as gt, AuthBetterAuthRuntimeOptions as h, AuthConsoleRoles as ht, AuthAccessConfiguration as i, AuthConsoleHostOptions as it, AuthRuntimeOnlyOptions as j, AuthEventListInput as jt, AuthRuntimeContext as k, AuthEventAggregates as kt, AuthAnonymousAuthorization as l, AuthConsoleOrganization as lt, AuthBetterAuthOptions as m, AuthConsoleQuery as mt, AuthAccessAuthorize as n, AuthConsoleFieldPolicy as nt, AuthAccessPolicyContext as o, AuthConsoleList as ot, AuthAuthorization as p, AuthConsolePolicy as pt, AuthConsoleActivityQuery as q, AuthAccessAuthorizeResult as r, AuthConsoleFieldType as rt, AuthAccessRoute as s, AuthConsoleMutation as st, AuthAccessAuthorizationContext as t, AuthConsoleField as tt, AuthAnonymousAuthorize as u, AuthConsoleOrganizationDetail as ut, AuthDefinitionInput as v, AuthConsoleUser as vt, AuthOptions as w, AuthPageMode as wt, AuthDeleteAccountOptions as x, authConsoleActionNames as xt, AuthDefinitionOptions as y, AuthConsoleUserDetail as yt, AuthViteHubOptions as z, createDatabaseAuthEventStore as zt };
@@ -1,12 +1,12 @@
1
1
  import { t as invariant } from "./invariant-Dj2R1eMr.js";
2
- import { t as createNitroServerKit } from "./nitro-kit-Bg4xUZAI.js";
2
+ import { t as createNitroServerKit } from "./nitro-kit-BumWIKa5.js";
3
3
  import { t as isRecord$1 } from "./object-CAK6UYR5.js";
4
4
  import { r as resolveAccessRoutePath, t as accessRouteSyntaxError } from "./application-path-zKi7NrvK.js";
5
- import { t as authErrorDiagnostics } from "./error-diagnostics-BssJr_2t.js";
6
- import { a as normalizeAuthBasePath, n as assertAuthPages } from "./access-pages-BwImVHN_.js";
7
- import { a as authDatabaseSchemaError, i as authDatabasePlacementError, n as authDatabaseAdditionalFieldsError, o as authMemoryDatabaseError, t as assertAuthDatabaseIdStrategy } from "./database-options-DQ-8qYMl.js";
8
- import { i as resolveAuthTableSpecs, n as authSqlName } from "./table-specs-jw0jjU6l.js";
9
- import { i as resetAuth } from "./runtime-state-DtKUfxKq.js";
5
+ import { t as authErrorDiagnostics } from "./error-diagnostics-CUPwukgE.js";
6
+ import { a as normalizeAuthBasePath, n as assertAuthPages } from "./access-pages-9aKr6z-k.js";
7
+ import { a as authDatabaseSchemaError, i as authDatabasePlacementError, n as authDatabaseAdditionalFieldsError, o as authMemoryDatabaseError, t as assertAuthDatabaseIdStrategy } from "./database-options-B87hDU4j.js";
8
+ import { i as resolveAuthTableSpecs, n as authSqlName } from "./table-specs-CCSY4tiS.js";
9
+ import { n as resetAuth } from "./runtime-state-C0Rd1W4m.js";
10
10
  import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
11
11
  import { basename, dirname, join, parse, relative, resolve } from "node:path";
12
12
  import { fileURLToPath } from "node:url";
@@ -639,6 +639,7 @@ function readAuthDatabaseImports(module) {
639
639
  /** The plugin factories whose tables `authDatabase()` adds, by the module that exports them. */
640
640
  const authSchemaPluginImports = {
641
641
  "better-auth/plugins": {
642
+ admin: "admin",
642
643
  anonymous: "anonymous",
643
644
  lastLoginMethod: "lastLoginMethod",
644
645
  phoneNumber: "phoneNumber",
@@ -648,6 +649,9 @@ const authSchemaPluginImports = {
648
649
  "@better-auth/api-key": { apiKey: "apiKey" },
649
650
  "@better-auth/stripe": { stripe: "stripe" }
650
651
  };
652
+ function pluginFactoriesOf(source) {
653
+ return authSchemaPluginImports[source.startsWith("better-auth/plugins/") ? "better-auth/plugins" : source];
654
+ }
651
655
  const viteExtensions = [
652
656
  ".mjs",
653
657
  ".js",
@@ -679,6 +683,9 @@ function resolveLocalModule(importer, specifier) {
679
683
  ].find(isFile);
680
684
  }
681
685
  const nameOf = (node) => node.type === "Identifier" ? node.name : String(node.value);
686
+ function staticMemberName(member) {
687
+ return member.computed ? staticString(member.property) : member.property.type === "Identifier" ? member.property.name : void 0;
688
+ }
682
689
  function addBoundNames(pattern, names) {
683
690
  walk(pattern, (node) => {
684
691
  if (node.type === "Identifier") names.push(node.name);
@@ -694,7 +701,9 @@ function readModuleBindings(module) {
694
701
  imports: /* @__PURE__ */ new Map(),
695
702
  exports: /* @__PURE__ */ new Map(),
696
703
  exportAll: [],
697
- pluginFactories: /* @__PURE__ */ new Map()
704
+ exportAllFactories: [],
705
+ pluginFactories: /* @__PURE__ */ new Map(),
706
+ pluginNamespaces: /* @__PURE__ */ new Map()
698
707
  };
699
708
  const localFile = (specifier) => specifier.startsWith("./") || specifier.startsWith("../") ? resolveLocalModule(module.file, specifier) : void 0;
700
709
  const declare = (name, node) => bindings.declarations.set(name, [...bindings.declarations.get(name) ?? [], node]);
@@ -713,11 +722,12 @@ function readModuleBindings(module) {
713
722
  for (const statement of module.program.body) if (statement.type === "ImportDeclaration") {
714
723
  if (statement.importKind === "type") continue;
715
724
  const source = statement.source.value;
716
- const factories = authSchemaPluginImports[source.startsWith("better-auth/plugins/") ? "better-auth/plugins" : source];
725
+ const factories = pluginFactoriesOf(source);
717
726
  const file = localFile(source);
718
727
  for (const specifier of statement.specifiers) {
719
728
  if (specifier.type === "ImportSpecifier" && specifier.importKind === "type") continue;
720
729
  const imported = specifier.type === "ImportSpecifier" ? nameOf(specifier.imported) : specifier.type === "ImportDefaultSpecifier" ? "default" : "*";
730
+ if (factories && imported === "*") bindings.pluginNamespaces.set(specifier.local.name, factories);
721
731
  if (factories && Object.hasOwn(factories, imported)) bindings.pluginFactories.set(specifier.local.name, factories[imported]);
722
732
  if (file) bindings.imports.set(specifier.local.name, {
723
733
  file,
@@ -728,6 +738,7 @@ function readModuleBindings(module) {
728
738
  if (statement.exportKind === "type") continue;
729
739
  if (statement.declaration) readDeclaration(statement.declaration, true);
730
740
  const file = statement.source ? localFile(statement.source.value) : void 0;
741
+ const factories = statement.source ? pluginFactoriesOf(statement.source.value) : void 0;
731
742
  for (const specifier of statement.specifiers) {
732
743
  if (specifier.exportKind === "type") continue;
733
744
  const local = nameOf(specifier.local);
@@ -736,16 +747,19 @@ function readModuleBindings(module) {
736
747
  file,
737
748
  imported: local
738
749
  });
750
+ else bindings.exports.set(nameOf(specifier.exported), { plugin: factories && Object.hasOwn(factories, local) ? factories[local] : void 0 });
739
751
  } else bindings.exports.set(nameOf(specifier.exported), { local });
740
752
  }
741
753
  } else if (statement.type === "ExportAllDeclaration") {
742
- const file = statement.exportKind === "type" ? void 0 : localFile(statement.source.value);
743
- if (!file) continue;
744
- if (statement.exported) bindings.exports.set(nameOf(statement.exported), {
754
+ if (statement.exportKind === "type") continue;
755
+ const factories = statement.exported ? void 0 : pluginFactoriesOf(statement.source.value);
756
+ if (factories) bindings.exportAllFactories.push(factories);
757
+ const file = localFile(statement.source.value);
758
+ if (statement.exported) bindings.exports.set(nameOf(statement.exported), file ? {
745
759
  file,
746
760
  imported: "*"
747
- });
748
- else bindings.exportAll.push(file);
761
+ } : { plugin: void 0 });
762
+ else if (file) bindings.exportAll.push(file);
749
763
  } else if (statement.type === "ExportDefaultDeclaration") {
750
764
  declare("default", statement.declaration);
751
765
  bindings.exports.set("default", { local: "default" });
@@ -759,21 +773,48 @@ function readModuleBindings(module) {
759
773
  * local modules it imports. The whole module counts for the Definition. In an imported module, only the exports that
760
774
  * the importer uses count, with the declarations and imports that they use.
761
775
  */
762
- function readModuleNeeds(module, needs) {
776
+ function readModuleNeeds(module, needs, exportedFactory) {
763
777
  const bindings = readModuleBindings(module);
764
778
  const plugins = /* @__PURE__ */ new Set();
765
779
  const imports = [];
766
- const need = (file, imported) => imports.push([file, imported === "*" ? "all" : /* @__PURE__ */ new Set([imported])]);
767
- const collectCalls = (node, references) => walk(node, (child) => {
780
+ const need = (file, imported) => imports.push([file, /* @__PURE__ */ new Set([imported])]);
781
+ const needImport = ({ file, imported }) => imported === "*" ? imports.push([file, "all"]) : need(file, imported);
782
+ const calledFactory = (callee) => {
783
+ if (callee.type === "Identifier") {
784
+ const imported = bindings.imports.get(callee.name);
785
+ return bindings.pluginFactories.get(callee.name) ?? (imported && imported.imported !== "*" ? exportedFactory(imported.file, imported.imported) : void 0);
786
+ }
787
+ if (callee.type !== "MemberExpression" || callee.object.type !== "Identifier") return void 0;
788
+ const property = staticMemberName(callee);
789
+ if (property === void 0) return void 0;
790
+ const factories = bindings.pluginNamespaces.get(callee.object.name);
791
+ if (factories) return Object.hasOwn(factories, property) ? factories[property] : void 0;
792
+ const imported = bindings.imports.get(callee.object.name);
793
+ return imported?.imported === "*" ? exportedFactory(imported.file, property) : void 0;
794
+ };
795
+ const collectCalls = (node, references) => walk(node, (child, parent) => {
768
796
  if (child.type === "ImportDeclaration") return false;
769
- if (child.type === "CallExpression" && child.callee.type === "Identifier" && bindings.pluginFactories.has(child.callee.name)) plugins.add(bindings.pluginFactories.get(child.callee.name));
770
- if (child.type === "Identifier") references?.add(child.name);
797
+ const plugin = child.type === "CallExpression" ? calledFactory(child.callee) : void 0;
798
+ if (plugin) plugins.add(plugin);
799
+ if (child.type !== "Identifier") return;
800
+ if (parent?.type === "MemberExpression") {
801
+ if (parent.property === child && !parent.computed) return;
802
+ if (parent.object === child) {
803
+ const imported = bindings.imports.get(child.name);
804
+ const member = staticMemberName(parent);
805
+ if (imported?.imported === "*" && member !== void 0) {
806
+ need(imported.file, member);
807
+ return;
808
+ }
809
+ }
810
+ }
811
+ references.add(child.name);
771
812
  });
772
813
  if (needs === "all") {
773
814
  const references = /* @__PURE__ */ new Set();
774
815
  collectCalls(module.program, references);
775
- for (const [name, { file, imported }] of bindings.imports) if (references.has(name)) need(file, imported);
776
- for (const [, target] of bindings.exports) if ("file" in target) need(target.file, target.imported);
816
+ for (const [name, imported] of bindings.imports) if (references.has(name)) needImport(imported);
817
+ for (const target of bindings.exports.values()) if ("file" in target) needImport(target);
777
818
  return {
778
819
  plugins: [...plugins],
779
820
  imports
@@ -783,15 +824,15 @@ function readModuleNeeds(module, needs) {
783
824
  for (const name of needs) {
784
825
  const target = bindings.exports.get(name);
785
826
  if (!target) for (const file of bindings.exportAll) need(file, name);
786
- else if ("file" in target) need(target.file, target.imported);
787
- else locals.push(target.local);
827
+ else if ("file" in target) needImport(target);
828
+ else if ("local" in target) locals.push(target.local);
788
829
  }
789
830
  const reached = /* @__PURE__ */ new Set();
790
831
  for (let local = locals.pop(); local !== void 0; local = locals.pop()) {
791
832
  if (reached.has(local)) continue;
792
833
  reached.add(local);
793
834
  const imported = bindings.imports.get(local);
794
- if (imported) need(imported.file, imported.imported);
835
+ if (imported) needImport(imported);
795
836
  const references = /* @__PURE__ */ new Set();
796
837
  for (const declaration of bindings.declarations.get(local) ?? []) collectCalls(declaration, references);
797
838
  for (const reference of references) if (bindings.declarations.has(reference) || bindings.imports.has(reference)) locals.push(reference);
@@ -808,6 +849,32 @@ function readModuleNeeds(module, needs) {
808
849
  function readDefinitionSchemaPlugins(definition) {
809
850
  const plugins = /* @__PURE__ */ new Set();
810
851
  const modules = /* @__PURE__ */ new Map([[definition.file, definition]]);
852
+ const moduleOf = (file) => {
853
+ let module = modules.get(file);
854
+ if (!module) modules.set(file, module = scanModule(readFileSync(file, "utf8"), file));
855
+ return module;
856
+ };
857
+ const bindingsByFile = /* @__PURE__ */ new Map();
858
+ const exportedFactory = (file, name, seen = /* @__PURE__ */ new Set()) => {
859
+ const key = `${file}\0${name}`;
860
+ if (seen.has(key)) return void 0;
861
+ seen.add(key);
862
+ let bindings = bindingsByFile.get(file);
863
+ if (!bindings) bindingsByFile.set(file, bindings = readModuleBindings(moduleOf(file)));
864
+ const target = bindings.exports.get(name);
865
+ if (target && "plugin" in target) return target.plugin;
866
+ if (target && "file" in target) return exportedFactory(target.file, target.imported, seen);
867
+ if (target) {
868
+ const imported = bindings.imports.get(target.local);
869
+ return bindings.pluginFactories.get(target.local) ?? (imported && imported.imported !== "*" ? exportedFactory(imported.file, imported.imported, seen) : void 0);
870
+ }
871
+ const factories = bindings.exportAllFactories.find((item) => Object.hasOwn(item, name));
872
+ if (factories) return factories[name];
873
+ for (const exported of bindings.exportAll) {
874
+ const plugin = exportedFactory(exported, name, seen);
875
+ if (plugin) return plugin;
876
+ }
877
+ };
811
878
  const done = /* @__PURE__ */ new Map();
812
879
  const queue = [[definition.file, "all"]];
813
880
  for (let item = queue.shift(); item; item = queue.shift()) {
@@ -817,9 +884,7 @@ function readDefinitionSchemaPlugins(definition) {
817
884
  const fresh = needs === "all" ? "all" : new Set([...needs].filter((name) => !previous?.has(name)));
818
885
  if (fresh !== "all" && !fresh.size) continue;
819
886
  done.set(file, fresh === "all" ? "all" : /* @__PURE__ */ new Set([...previous ?? [], ...fresh]));
820
- let module = modules.get(file);
821
- if (!module) modules.set(file, module = scanModule(readFileSync(file, "utf8"), file));
822
- const result = readModuleNeeds(module, fresh);
887
+ const result = readModuleNeeds(moduleOf(file), fresh, exportedFactory);
823
888
  for (const plugin of result.plugins) plugins.add(plugin);
824
889
  queue.push(...result.imports);
825
890
  }
@@ -1609,6 +1674,7 @@ function mergeNitroAuthHandler(value, config, dev) {
1609
1674
  middleware: true,
1610
1675
  route: "/**"
1611
1676
  }] : []];
1677
+ kit.addPlugin(ownModule(import.meta.url, "runtime/client-request-plugin"), "start");
1612
1678
  for (const handler of authHandlers) kit.addHandler(handler);
1613
1679
  const merged = kit.config;
1614
1680
  const guards = /* @__PURE__ */ new Set([cachedAccessRouteGuardName, memoryDatabaseGuardName]);
@@ -1680,7 +1746,7 @@ function hubAuth(options, internalOptions = {}) {
1680
1746
  export: dialect === "postgresql" ? "authPostgresSchema" : "authSqliteSchema"
1681
1747
  },
1682
1748
  tables,
1683
- reason: "Stores the Better Auth users, sessions, accounts, and verifications, the admin() fields, the tables and columns of the plugins and additional fields that the Auth Definition adds, and the Console MCP OAuth clients and tokens of authDatabase()."
1749
+ reason: "Stores the Better Auth users, sessions, accounts, and verifications, the tables and columns of the plugins and additional fields that the Auth Definition adds, and the Console MCP OAuth clients and tokens of authDatabase()."
1684
1750
  }];
1685
1751
  },
1686
1752
  inspect: () => {
package/dist/vite.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /// <reference path="./host-declarations.d.ts" />
2
- import { U as ResolvedAuthViteConfig, w as AuthOptions } from "./types-BHSgxyvV.js";
2
+ import { U as ResolvedAuthViteConfig, w as AuthOptions } from "./types-DmH31d2t.js";
3
3
  import { n as ViteHubCliPluginMetadata } from "./cli-C5pAfY4x.js";
4
4
  import { Plugin } from "vite";
5
5
  interface ViteHubDefinitionField {
package/dist/vite.js CHANGED
@@ -1 +1 @@
1
- export { t as AUTH_ABILITIES_ID, n as AUTH_CLIENT_ID, r as AUTH_DEFINITION_ID, i as AUTH_SERVER_ID, a as AUTH_VITE_PLUGIN_NAME, o as createAuthNitroConfig, s as hubAuth, l as resolveAuthViteConfig, c as writeNuxtAuthDefinition } from "./vite-D1xC9n1O.js";
1
+ export { t as AUTH_ABILITIES_ID, n as AUTH_CLIENT_ID, r as AUTH_DEFINITION_ID, i as AUTH_SERVER_ID, a as AUTH_VITE_PLUGIN_NAME, o as createAuthNitroConfig, s as hubAuth, l as resolveAuthViteConfig, c as writeNuxtAuthDefinition } from "./vite-CpWhT1Wi.js";
package/dist/vue.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /// <reference path="./host-declarations.d.ts" />
2
- import { a as AbilityRefusal, i as AbilityName, t as AbilityArgs } from "./abilities-3L1Y5Pnw.js";
3
- import { S as AuthFor, _ as AuthDefinition } from "./types-BHSgxyvV.js";
2
+ import { a as AbilityRefusal, i as AbilityName, t as AbilityArgs } from "./abilities-BYOcyQ9B.js";
3
+ import { S as AuthFor, _ as AuthDefinition } from "./types-DmH31d2t.js";
4
4
  import { n as AbilityErrorData } from "./ability-error-C1c30O6E.js";
5
5
  import { BetterAuthClientOptions } from "better-auth";
6
6
  import { ComputedRef, VNode } from "vue";
package/dist/vue.js CHANGED
@@ -1,4 +1,4 @@
1
- import { n as checkAbility, t as AbilityError } from "./ability-error-BHhPkrZd.js";
1
+ import { n as checkAbility, t as AbilityError } from "./ability-error-D3-u8k1A.js";
2
2
  import { i as resolveAuthMountPath } from "./application-path-zKi7NrvK.js";
3
3
  import { a as setRequestFetchResolver, i as setNuxtErrorFactory, n as setDefaultAuthBasePath, o as setSessionSeedResolver, r as setNuxtAppResolver, s as setSignOutHandler, t as authNuxtBridge } from "./nuxt-bridge-pRyfYD5c.js";
4
4
  import abilities from "#vitehub/auth/abilities";