@vite-hub/auth 0.5.0 → 0.6.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 (92) hide show
  1. package/README.md +3 -3
  2. package/dist/{abilities-9jC7iuN0.d.ts → abilities-D3XlrYDw.d.ts} +1 -3
  3. package/dist/abilities.d.ts +1 -1
  4. package/dist/abilities.js +1 -2
  5. package/dist/{ability-error-DUWJ6Q1W.d.ts → ability-error-C1c30O6E.d.ts} +0 -4
  6. package/dist/{ability-error-DmnUGicq.js → ability-error-D3-u8k1A.js} +3 -5
  7. package/dist/{access-pages-FNQTyGRD.js → access-pages-9aKr6z-k.js} +3 -5
  8. package/dist/{admin-claim-code-CDipqeAU.js → admin-claim-code-C3X_U43x.js} +1 -2
  9. package/dist/agent.d.ts +1 -3
  10. package/dist/agent.js +5 -6
  11. package/dist/{application-path-DuTpfGFj.js → application-path-zKi7NrvK.js} +1 -2
  12. package/dist/{auth-instance-zYMjldPG.js → auth-instance-BpI9Ps8A.js} +88 -91
  13. package/dist/{cli-NCtitmny.d.ts → cli-C5pAfY4x.d.ts} +0 -6
  14. package/dist/cli.d.ts +2 -4
  15. package/dist/cli.js +3 -4
  16. package/dist/{console-runtime-CuXRDhGy.js → console-runtime-CaIXVtB_.js} +10 -211
  17. package/dist/console-runtime-DAjLTLrN.d.ts +32 -0
  18. package/dist/console-runtime.d.ts +3 -3
  19. package/dist/console-runtime.js +1 -2
  20. package/dist/{console-types-CmmnKGMx.js → console-types-NrX5TWl3.js} +3 -3
  21. package/dist/console.d.ts +3 -7
  22. package/dist/console.js +2 -3
  23. package/dist/{database-options-CcjUG-us.js → database-options-B87hDU4j.js} +2 -3
  24. package/dist/{database-schema-options-CTKCAfqW.js → database-schema-options-peXHNLkJ.js} +2 -3
  25. package/dist/database.d.ts +2 -4
  26. package/dist/database.js +6 -7
  27. package/dist/{definition-BFT9T6In.js → definition-BypPLIbI.js} +11 -17
  28. package/dist/{error-diagnostics-uEbxSY2G.js → error-diagnostics-CUPwukgE.js} +2 -3
  29. package/dist/{events-DJmO9a9I.js → events-BXU1_9mc.js} +5 -6
  30. package/dist/forward-sign-ins-BWXPPTRz.js +4 -0
  31. package/dist/forward.d.ts +25 -3
  32. package/dist/forward.js +43 -6
  33. package/dist/index.d.ts +3 -7
  34. package/dist/index.js +3 -3
  35. package/dist/internal/server.d.ts +3 -3
  36. package/dist/internal/server.js +4 -4
  37. package/dist/{invariant-DolT9EEx.js → invariant-Dj2R1eMr.js} +1 -2
  38. package/dist/{mcp-config-DRRlCAWN.js → mcp-config-C7srUMIZ.js} +2 -3
  39. package/dist/mcp-token-CmQbXbTu.d.ts +125 -0
  40. package/dist/{mcp-token-BhonlK9C.js → mcp-token-DzGivm7f.js} +47 -33
  41. package/dist/mcp.d.ts +2 -115
  42. package/dist/mcp.js +5 -6
  43. package/dist/{members-Cl3hFRjk.js → members-CwPIx10t.js} +10 -14
  44. package/dist/{nitro-kit-32CVgbWS.js → nitro-kit-BumWIKa5.js} +3 -4
  45. package/dist/{nuxt-bridge-Cl988STZ.js → nuxt-bridge-pRyfYD5c.js} +1 -2
  46. package/dist/nuxt.d.ts +1 -7
  47. package/dist/nuxt.js +6 -9
  48. package/dist/{object-Da1zyPCR.js → object-CAK6UYR5.js} +1 -2
  49. package/dist/{own-access-C8pwo_Kn.js → own-access-CYsakJiH.js} +3 -4
  50. package/dist/{own-access-CdgEICjO.d.ts → own-access-Dt-I5-PT.d.ts} +1 -3
  51. package/dist/{page-tools-shared-l4eyj53D.js → page-tools-shared-CtoKaNQZ.js} +1 -2
  52. package/dist/{presets-CHndEv5i.d.ts → presets-C6AtiRdI.d.ts} +0 -2
  53. package/dist/presets.d.ts +1 -1
  54. package/dist/presets.js +2 -3
  55. package/dist/{request-z6DHHmrb.js → request-Dpq7GO8B.js} +2 -4
  56. package/dist/runtime/console.d.ts +1 -1
  57. package/dist/runtime/console.js +2 -2
  58. package/dist/runtime/empty-abilities.d.ts +1 -3
  59. package/dist/runtime/empty-abilities.js +1 -2
  60. package/dist/runtime/empty-client.d.ts +0 -2
  61. package/dist/runtime/empty-client.js +1 -2
  62. package/dist/runtime/empty-definition.d.ts +1 -3
  63. package/dist/runtime/empty-definition.js +1 -2
  64. package/dist/runtime/nuxt.d.ts +1 -3
  65. package/dist/runtime/nuxt.js +1 -2
  66. package/dist/runtime/server.d.ts +2 -2
  67. package/dist/runtime/server.js +6 -7
  68. package/dist/runtime/vue-nuxt.d.ts +0 -2
  69. package/dist/runtime/vue-nuxt.js +5 -6
  70. package/dist/runtime-state-C0Rd1W4m.js +15 -0
  71. package/dist/schema.d.ts +1 -5
  72. package/dist/schema.js +2 -3
  73. package/dist/{server-Ci2i6p1S.d.ts → server-Cun232hb.d.ts} +14 -17
  74. package/dist/{server-B-zNtSvm.d.ts → server-DL9MSuyj.d.ts} +2 -6
  75. package/dist/{server-CyqLFm3L.js → server-_eUOlAJ8.js} +16 -18
  76. package/dist/server.d.ts +4 -3
  77. package/dist/server.js +2 -2
  78. package/dist/{session-cookies-CZmZS5QF.js → session-cookies-fR6Pv4kD.js} +6 -8
  79. package/dist/{set-cookie-DWIyCCJO.js → set-cookie-DVfi-nJX.js} +3 -5
  80. package/dist/{table-specs-D0VLp1U4.js → table-specs-CCSY4tiS.js} +17 -15
  81. package/dist/{table-specs-BhWz_U0M.d.ts → table-specs-P4LvbOlX.d.ts} +28 -23
  82. package/dist/test.d.ts +2 -4
  83. package/dist/test.js +3 -4
  84. package/dist/{types-gl-myjZc.d.ts → types-BP9_XUr9.d.ts} +4 -30
  85. package/dist/{vite-QKjsPLwP.js → vite-Dem1i1rL.js} +111 -62
  86. package/dist/vite.d.ts +3 -14
  87. package/dist/vite.js +1 -2
  88. package/dist/vue.d.ts +3 -7
  89. package/dist/vue.js +4 -5
  90. package/package.json +32 -31
  91. package/dist/console-runtime-Dqidb3zF.d.ts +0 -73
  92. package/dist/runtime-state-ojQCzKOc.js +0 -25
package/dist/cli.js CHANGED
@@ -1,6 +1,6 @@
1
- import { t as authErrorDiagnostics } from "./error-diagnostics-uEbxSY2G.js";
2
- import { n as adminClaimVariable, r as createAdminClaimCode, t as adminClaimHash } from "./admin-claim-code-CDipqeAU.js";
3
- //#region src/cli.ts
1
+ import { n as adminClaimVariable, r as createAdminClaimCode, t as adminClaimHash } from "./admin-claim-code-C3X_U43x.js";
2
+ import { t as authErrorDiagnostics } from "./error-diagnostics-CUPwukgE.js";
3
+ // src/cli.ts
4
4
  const usage = "vitehub auth events --url <auth-base-url> [--type <type>] [--user <id>] [--actor <actor>] [--from <ISO>] [--to <ISO>] [--cursor <cursor>] [--limit <1-200>] [--aggregate]";
5
5
  /** Read the app-owned, session-protected endpoint. No local or remote database credentials are needed. */
6
6
  function createAuthCliContributor(options = {}) {
@@ -104,5 +104,4 @@ function createAuthCliContributor(options = {}) {
104
104
  }]
105
105
  }] };
106
106
  }
107
- //#endregion
108
107
  export { createAuthCliContributor };
@@ -1,21 +1,15 @@
1
- import { n as adminClaimVariable } from "./admin-claim-code-CDipqeAU.js";
2
- import { m as adminsVariable, p as adminsPluginId, r as membersVariable, s as accessPolicyPluginId, u as adminClaimPluginId } from "./members-Cl3hFRjk.js";
3
- import { r as isAuthProcessMemoryDatabase } from "./runtime-state-ojQCzKOc.js";
4
- import { r as parseAuthEventList } from "./events-DJmO9a9I.js";
5
- import { n as authConsoleEventGroups, t as authConsoleActionNames } from "./console-types-CmmnKGMx.js";
1
+ import { m as adminsVariable, p as adminsPluginId, r as membersVariable, s as accessPolicyPluginId, u as adminClaimPluginId } from "./members-CwPIx10t.js";
2
+ import { n as adminClaimVariable } from "./admin-claim-code-C3X_U43x.js";
3
+ import { n as authConsoleEventGroups, t as authConsoleActionNames } from "./console-types-NrX5TWl3.js";
4
+ import { r as parseAuthEventList } from "./events-BXU1_9mc.js";
6
5
  import { defineErrors } from "@vite-hub/runtime";
7
- import { createAuthEndpoint } from "better-auth/api";
8
- import { setSessionCookie } from "better-auth/cookies";
9
- import { getAuthTables } from "better-auth/db";
10
6
  import { defineGrant } from "@vite-hub/runtime/internal/grant";
11
- //#region ../internal/src/runtime/user-agent.ts
7
+ // ../internal/src/runtime/user-agent.ts
12
8
  /** A short device label of a browser, such as `Chrome · macOS`, for lists of sessions. It never shows the user agent itself. */
13
9
  function userAgentDevice(userAgent) {
14
10
  return `${/Edg\//.test(userAgent) ? "Edge" : /Firefox\//.test(userAgent) ? "Firefox" : /Chrome\//.test(userAgent) ? "Chrome" : /Safari\//.test(userAgent) ? "Safari" : "Unknown browser"} · ${/iPhone|iPad/.test(userAgent) ? "iOS" : /Android/.test(userAgent) ? "Android" : /Windows/.test(userAgent) ? "Windows" : /Macintosh/.test(userAgent) ? "macOS" : /Linux/.test(userAgent) ? "Linux" : "Unknown device"}`;
15
11
  }
16
- //#endregion
17
- //#region src/console-runtime.ts
18
- const hostGuestProvider = "vitehub-site-guest";
12
+ // src/console-runtime.ts
19
13
  const string = (value) => typeof value === "string" ? value : "";
20
14
  const date = (value) => {
21
15
  const parsed = value instanceof Date ? value : new Date(typeof value === "string" || typeof value === "number" ? value : NaN);
@@ -103,8 +97,8 @@ const errors = defineErrors({
103
97
  fix: "Refresh the list and check the Auth Definition's plugins."
104
98
  },
105
99
  AUTH_CONSOLE_UNAVAILABLE: {
106
- why: ({ detail }) => detail ?? "Auth does not have the database, the `user.role` field, or the Better Auth plugin API that this operation needs.",
107
- fix: "Set `database: authDatabase()` from `vite-hub/auth/database`, which also adds the `user.role` field that Site access needs. With your own adapter and schema, add a nullable `role` text column to the `user` table, apply the migration, and declare the field with `user: { additionalFields: { role: { type: \"string\", required: false, input: false } } }`. For a plugin operation, add the plugin. With a custom schema, add the plugin fields to your schema and apply the database migration before using the plugin. The default `admin()` fields are `user.role`, `user.banned`, `user.banReason`, `user.banExpires`, and `session.impersonatedBy`."
100
+ why: ({ detail }) => detail ?? "Auth does not have the database or plugin API needed for this operation.",
101
+ fix: "Configure a database adapter and the required Better Auth plugin."
108
102
  },
109
103
  AUTH_CONSOLE_PROVIDER_FAILED: {
110
104
  why: "Better Auth or an app column reader could not complete the operation.",
@@ -256,27 +250,6 @@ function createAuthConsole(auth, policy = {}, events, host = {}) {
256
250
  const rows = await ctx.internalAdapter.listSessions(userId);
257
251
  return Array.isArray(rows) ? rows.map(record) : [];
258
252
  }
259
- async function hostSessionById(id) {
260
- const ctx = await context();
261
- if (!ctx.options.secondaryStorage) return await find("session", equality("id", id));
262
- const limit = 100;
263
- for (let offset = 0;; offset += limit) {
264
- const users = await ctx.adapter.findMany({
265
- model: "user",
266
- offset,
267
- limit,
268
- sortBy: {
269
- field: "id",
270
- direction: "asc"
271
- }
272
- });
273
- for (const user of users) {
274
- const session = (await storedSessions(string(user.id))).find((row) => string(row.id) === id);
275
- if (session) return session;
276
- }
277
- if (users.length < limit) return null;
278
- }
279
- }
280
253
  /**
281
254
  * The acting request for a check that only reads, such as whether the actor may impersonate a user. Without an app
282
255
  * account or a live session of the actor, the check runs without a request and refuses, as describe() does.
@@ -879,7 +852,7 @@ function createAuthConsole(auth, policy = {}, events, host = {}) {
879
852
  }
880
853
  const actionGrant = defineGrant("vitehub.auth.console.action", (action) => action);
881
854
  async function authorize(input, request) {
882
- if (input.action === "impersonate" && host.actor) throw authConsoleError(403, "Impersonation needs the browser's app session. Open it with a one-time link from the Console.");
855
+ if (input.action === "impersonate" && host.actor) throw authConsoleError(403, "Impersonation needs the browser's app session. Start it from the Console.");
883
856
  const description = await describe(request);
884
857
  if (!description.actions[input.action]?.enabled) throw authConsoleError(403, description.actions[input.action]?.reason ?? "Action not supported.");
885
858
  if (input.action === "editField") {
@@ -969,126 +942,6 @@ function createAuthConsole(auth, policy = {}, events, host = {}) {
969
942
  } : null
970
943
  };
971
944
  }
972
- /**
973
- * Better Auth's verification table, which needs a database adapter that every instance shares. The memory database
974
- * that Auth adds to a Definition without one lives in one process, so it does not count.
975
- */
976
- async function verifications() {
977
- const ctx = await context();
978
- if (!ctx.options.database || isAuthProcessMemoryDatabase(ctx.options.database) || !ctx.internalAdapter) throw authConsoleError(409, "One-time values need a Better Auth database adapter that every instance of the app shares.");
979
- return ctx.internalAdapter;
980
- }
981
- /** The Better Auth context for host users and sessions: the `user.role` field keeps the roles, a database keeps the rest. */
982
- async function hostContext() {
983
- const ctx = await context();
984
- if (!ctx.options.database || !ctx.internalAdapter || !ctx.authCookies || !ctx.secret || !ctx.sessionConfig) throw authConsoleError(409, "Signing a browser in from the Console needs a Better Auth database.");
985
- const role = getAuthTables(ctx.options).user?.fields.role;
986
- if (!role) throw authConsoleError(409, "Site access keeps permissions as roles in the `role` field of the Better Auth user, and your user table has no such field. Use `authDatabase()`, which adds it. With your own schema, add a nullable `role` text column to the `user` table, apply the migration, and declare the field in `defineAuth()`: `user: { additionalFields: { role: { type: \"string\", required: false, input: false } } }`.");
987
- if (role.input !== false) throw authConsoleError(409, "Site access keeps permissions as roles in `user.role`, and your `role` field lets users set it when they sign up or update their profile. Set `input: false` on the `role` field of `user.additionalFields` in `defineAuth()`.");
988
- if (role.returned === false) throw authConsoleError(409, "Site access needs `user.role` in the session so page tools can read its grants. Remove `returned: false` from your `role` field.");
989
- return {
990
- ...ctx,
991
- internalAdapter: ctx.internalAdapter,
992
- authCookies: ctx.authCookies,
993
- secret: ctx.secret,
994
- sessionConfig: ctx.sessionConfig
995
- };
996
- }
997
- async function isHostGuest(userId) {
998
- return Boolean(await find("account", [
999
- {
1000
- field: "providerId",
1001
- value: hostGuestProvider
1002
- },
1003
- {
1004
- field: "accountId",
1005
- value: userId
1006
- },
1007
- {
1008
- field: "userId",
1009
- value: userId
1010
- }
1011
- ]));
1012
- }
1013
- async function hostUser(input) {
1014
- const ctx = await hostContext();
1015
- const email = input.email?.trim().toLowerCase();
1016
- const existing = email ? await find("user", equality("email", email)) : null;
1017
- if (existing && existing.emailVerified !== true) throw authConsoleError(403, `The app has an account with ${email}, and its email is not verified. Verify the email of that account, or delete the account, then open the site again.`);
1018
- if (existing) {
1019
- const owned = new Set(input.owned ?? []);
1020
- const kept = roleList(existing.role || string(adminPlugin(ctx.options).settings.defaultRole) || "user").filter((role) => !owned.has(role));
1021
- const roles = [.../* @__PURE__ */ new Set([...kept, ...input.roles])];
1022
- await ctx.internalAdapter.updateUser(string(existing.id), { role: roles.join(",") });
1023
- return {
1024
- id: string(existing.id),
1025
- roles
1026
- };
1027
- }
1028
- const roles = [...new Set(input.roles)];
1029
- const user = await ctx.internalAdapter.createUser({
1030
- email: email || `guest-${crypto.randomUUID()}@guests.invalid`,
1031
- emailVerified: Boolean(email),
1032
- name: input.name,
1033
- ...input.image ? { image: input.image } : {},
1034
- role: roles.join(",")
1035
- }, { method: "admin" });
1036
- if (!email && !await ctx.internalAdapter.createAccount({
1037
- providerId: hostGuestProvider,
1038
- accountId: user.id,
1039
- userId: user.id
1040
- })) throw authConsoleError(409, "Better Auth did not store the Site access guest account.");
1041
- return {
1042
- id: user.id,
1043
- roles
1044
- };
1045
- }
1046
- async function hostSession(userId, request) {
1047
- const ctx = await hostContext();
1048
- const { headers } = await createAuthEndpoint.serverOnly({ method: "POST" }, async (endpoint) => {
1049
- const user = await endpoint.context.internalAdapter.findUserById(userId);
1050
- if (!user) throw authConsoleError(404, "User not found.");
1051
- const session = await endpoint.context.internalAdapter.createSession(userId);
1052
- await setSessionCookie(endpoint, {
1053
- session,
1054
- user
1055
- }, false);
1056
- })({
1057
- context: ctx,
1058
- headers: request.headers,
1059
- returnHeaders: true
1060
- });
1061
- return new Headers(headers.getSetCookie().map((cookie) => ["set-cookie", cookie]));
1062
- }
1063
- async function hostSessions(roles) {
1064
- const holders = await (await hostContext()).adapter.findMany({
1065
- model: "user",
1066
- where: roles.map((role) => ({
1067
- field: "role",
1068
- operator: "contains",
1069
- value: role,
1070
- connector: "OR"
1071
- })),
1072
- limit: 1e3
1073
- });
1074
- const now = Date.now();
1075
- return (await Promise.all(holders.filter((user) => roleList(user.role).some((role) => roles.includes(role))).map(async (user) => {
1076
- const userId = string(user.id);
1077
- const userRoles = roleList(user.role);
1078
- const guest = await isHostGuest(userId);
1079
- if (!userRoles.some((role) => roles.includes(role) && (role !== "guest" || guest))) return [];
1080
- return (await storedSessions(userId)).filter((session) => new Date(date(session.expiresAt)).getTime() > now).map((session) => ({
1081
- id: string(session.id),
1082
- user: userSummary(user),
1083
- roles: userRoles,
1084
- guest,
1085
- device: userAgentDevice(string(session.userAgent)),
1086
- createdAt: date(session.createdAt),
1087
- updatedAt: date(session.updatedAt),
1088
- expiresAt: date(session.expiresAt)
1089
- }));
1090
- }))).flat().sort((left, right) => right.updatedAt.localeCompare(left.updatedAt));
1091
- }
1092
945
  async function stopImpersonating(request) {
1093
946
  if (host.bearer) throw authConsoleError(403, "Impersonation needs the browser's app session.");
1094
947
  if (!host.impersonation) throw authConsoleError(403, "Impersonation is off in the Console configuration.");
@@ -1130,56 +983,7 @@ function createAuthConsole(auth, policy = {}, events, host = {}) {
1130
983
  return await mutate(input, acting, await authorize(input, acting));
1131
984
  }),
1132
985
  stopImpersonating: (request) => result(() => stopImpersonating(request)),
1133
- session: (request) => result(() => sessionUser(request)),
1134
- saveVerification: (identifier, value, expiresAt) => result(async () => {
1135
- await (await verifications()).createVerificationValue({
1136
- identifier,
1137
- value,
1138
- expiresAt
1139
- });
1140
- }),
1141
- consumeVerification: (identifier) => result(async () => (await (await verifications()).consumeVerificationValue(identifier))?.value ?? null),
1142
- listVerifications: (prefix) => result(async () => {
1143
- await verifications();
1144
- const rows = await (await context()).adapter.findMany({
1145
- model: "verification",
1146
- where: [{
1147
- field: "identifier",
1148
- operator: "starts_with",
1149
- value: prefix
1150
- }],
1151
- limit: 1e3
1152
- });
1153
- const now = Date.now();
1154
- return rows.map((row) => ({
1155
- identifier: row.identifier,
1156
- value: row.value,
1157
- expiresAt: new Date(row.expiresAt)
1158
- })).filter((row) => row.expiresAt.getTime() > now);
1159
- }),
1160
- deleteVerification: (identifier) => result(async () => {
1161
- await (await verifications()).deleteVerificationByIdentifier(identifier);
1162
- }),
1163
- hostUser: (input) => result(() => hostUser(input)),
1164
- checkHost: () => result(async () => {
1165
- await hostContext();
1166
- }),
1167
- hostSession: (userId, request) => result(() => hostSession(userId, request)),
1168
- hostSessions: (roles) => result(() => hostSessions(roles)),
1169
- revokeHostSession: (id) => result(async () => {
1170
- const ctx = await hostContext();
1171
- const session = await hostSessionById(id);
1172
- if (!session) throw authConsoleError(404, "No session has this id. It ended, or someone revoked it.");
1173
- const userId = string(session.userId);
1174
- const guest = await isHostGuest(userId);
1175
- await ctx.internalAdapter.deleteSession(string(session.token));
1176
- if (guest) {
1177
- await ctx.internalAdapter.deleteUserSessions(userId);
1178
- await ctx.internalAdapter.deleteAccounts(userId);
1179
- await ctx.internalAdapter.deleteUser(userId);
1180
- }
1181
- return { removedUser: guest };
1182
- })
986
+ session: (request) => result(() => sessionUser(request))
1183
987
  };
1184
988
  }
1185
989
  /** The value of Better Auth's session cookie for a token: the token and its HMAC-SHA256 signature. */
@@ -1192,9 +996,4 @@ async function signedSessionToken(secret, token) {
1192
996
  const signature = new Uint8Array(await crypto.subtle.sign("HMAC", key, encoder.encode(token)));
1193
997
  return encodeURIComponent(`${token}.${btoa(String.fromCharCode(...signature))}`);
1194
998
  }
1195
- /** The roles of `admin()`'s comma-separated `user.role`. */
1196
- function roleList(value) {
1197
- return string(value).split(",").map((role) => role.trim()).filter(Boolean);
1198
- }
1199
- //#endregion
1200
999
  export { describeAuthConsoleFields as n, createAuthConsole as t };
@@ -0,0 +1,32 @@
1
+ import { Ft as AuthEventStore, J as AuthConsoleAgent, K as AuthConsoleActivity, Z as AuthConsoleDescription, _t as AuthConsoleSessionUser, ct as AuthConsoleOptions, dt as AuthConsoleOverview, gt as AuthConsoleSession, it as AuthConsoleHostOptions, lt as AuthConsoleOrganization, mt as AuthConsoleQuery, ot as AuthConsoleList, q as AuthConsoleActivityQuery, st as AuthConsoleMutation, tt as AuthConsoleField, ut as AuthConsoleOrganizationDetail, vt as AuthConsoleUser, yt as AuthConsoleUserDetail } from "./types-BP9_XUr9.js";
2
+ import { Result } from "@vite-hub/runtime";
3
+ import { AuthContext, BetterAuthOptions, DBAdapter } from "better-auth";
4
+ interface AuthConsole {
5
+ describe(request?: Request): Promise<Result<AuthConsoleDescription, AuthConsoleErrorCode>>;
6
+ overview(): Promise<Result<AuthConsoleOverview, AuthConsoleErrorCode>>;
7
+ activity(query?: AuthConsoleActivityQuery): Promise<Result<AuthConsoleActivity, AuthConsoleErrorCode>>;
8
+ users(query?: AuthConsoleQuery): Promise<Result<AuthConsoleList<AuthConsoleUser>, AuthConsoleErrorCode>>;
9
+ /** With `request`, the impersonation target check also counts the `impersonate-admins` permission of its session. */
10
+ user(id: string, request?: Request): Promise<Result<AuthConsoleUserDetail, AuthConsoleErrorCode>>;
11
+ sessions(query?: AuthConsoleQuery): Promise<Result<AuthConsoleList<AuthConsoleSession>, AuthConsoleErrorCode>>;
12
+ organizations(query?: AuthConsoleQuery): Promise<Result<AuthConsoleList<AuthConsoleOrganization>, AuthConsoleErrorCode>>;
13
+ organization(id: string, query?: AuthConsoleQuery): Promise<Result<AuthConsoleOrganizationDetail, AuthConsoleErrorCode>>;
14
+ agents(query?: AuthConsoleQuery): Promise<Result<AuthConsoleList<AuthConsoleAgent>, AuthConsoleErrorCode>>;
15
+ execute(input: AuthConsoleMutation, request: Request): Promise<Result<Response, AuthConsoleErrorCode>>;
16
+ /** End the impersonation of the request's app session and restore the administrator's session cookies. */
17
+ stopImpersonating(request: Request): Promise<Result<Response, AuthConsoleErrorCode>>;
18
+ /** The app session of the request's cookies, read from the database, or `null` without one. */
19
+ session(request: Request): Promise<Result<AuthConsoleSessionUser | null, AuthConsoleErrorCode>>;
20
+ }
21
+ type ConsoleAdapter = Pick<DBAdapter, "findMany" | "findOne" | "count">;
22
+ type AuthConsoleErrorCode = "AUTH_CONSOLE_INVALID_REQUEST" | "AUTH_CONSOLE_FORBIDDEN" | "AUTH_CONSOLE_NOT_FOUND" | "AUTH_CONSOLE_UNAVAILABLE" | "AUTH_CONSOLE_PROVIDER_FAILED";
23
+ /** Only additional fields that Better Auth allows in output reach the Console. */
24
+ declare function describeAuthConsoleFields(options: BetterAuthOptions, policy?: AuthConsoleOptions): AuthConsoleField[];
25
+ declare function createAuthConsole(auth: {
26
+ api: object;
27
+ $context: Promise<{
28
+ adapter: ConsoleAdapter;
29
+ options: BetterAuthOptions;
30
+ } & Partial<Pick<AuthContext, "authCookies" | "internalAdapter" | "secret" | "sessionConfig">>>;
31
+ }, policy?: AuthConsoleOptions, events?: AuthEventStore, host?: AuthConsoleHostOptions): AuthConsole;
32
+ export { describeAuthConsoleFields as i, AuthConsoleErrorCode as n, createAuthConsole as r, AuthConsole as t };
@@ -1,3 +1,3 @@
1
- import { $ as AuthConsoleEventGroup, Ct as authConsoleActionNames, G as AuthConsoleAction, J as AuthConsoleAgent, K as AuthConsoleActivity, Q as AuthConsoleEvent, St as AuthConsoleValue, X as AuthConsoleColumn, Y as AuthConsoleCapability, Z as AuthConsoleDescription, _t as AuthConsoleRoles, at as AuthConsoleHostSession, bt as AuthConsoleUser, ct as AuthConsoleList, dt as AuthConsoleOrganization, et as AuthConsoleEventUser, ft as AuthConsoleOrganizationDetail, gt as AuthConsoleQuery, ht as AuthConsolePolicy, it as AuthConsoleHostOptions, lt as AuthConsoleMutation, mt as AuthConsolePage, nt as AuthConsoleFieldPolicy, ot as AuthConsoleHostUserInput, pt as AuthConsoleOverview, q as AuthConsoleActivityQuery, rt as AuthConsoleFieldType, st as AuthConsoleImpersonation, tt as AuthConsoleField, ut as AuthConsoleOptions, vt as AuthConsoleSession, wt as authConsoleEventGroups, xt as AuthConsoleUserDetail, yt as AuthConsoleSessionUser } from "./types-gl-myjZc.js";
2
- import { i as describeAuthConsoleFields, n as AuthConsoleErrorCode, r as createAuthConsole, t as AuthConsole } from "./console-runtime-Dqidb3zF.js";
3
- export { AuthConsole, type AuthConsoleAction, type AuthConsoleActivity, type AuthConsoleActivityQuery, type AuthConsoleAgent, type AuthConsoleCapability, type AuthConsoleColumn, type AuthConsoleDescription, AuthConsoleErrorCode, type AuthConsoleEvent, type AuthConsoleEventGroup, type AuthConsoleEventUser, type AuthConsoleField, type AuthConsoleFieldPolicy, type AuthConsoleFieldType, type AuthConsoleHostOptions, type AuthConsoleHostSession, type AuthConsoleHostUserInput, type AuthConsoleImpersonation, type AuthConsoleList, type AuthConsoleMutation, type AuthConsoleOptions, type AuthConsoleOrganization, type AuthConsoleOrganizationDetail, type AuthConsoleOverview, type AuthConsolePage, type AuthConsolePolicy, type AuthConsoleQuery, type AuthConsoleRoles, type AuthConsoleSession, type AuthConsoleSessionUser, type AuthConsoleUser, type AuthConsoleUserDetail, type AuthConsoleValue, type authConsoleActionNames, type authConsoleEventGroups, createAuthConsole, describeAuthConsoleFields };
1
+ import { $ as AuthConsoleEventGroup, G as AuthConsoleAction, J as AuthConsoleAgent, K as AuthConsoleActivity, Q as AuthConsoleEvent, St as authConsoleEventGroups, X as AuthConsoleColumn, Y as AuthConsoleCapability, Z as AuthConsoleDescription, _t as AuthConsoleSessionUser, at as AuthConsoleImpersonation, bt as AuthConsoleValue, ct as AuthConsoleOptions, dt as AuthConsoleOverview, et as AuthConsoleEventUser, ft as AuthConsolePage, gt as AuthConsoleSession, ht as AuthConsoleRoles, it as AuthConsoleHostOptions, lt as AuthConsoleOrganization, mt as AuthConsoleQuery, nt as AuthConsoleFieldPolicy, ot as AuthConsoleList, pt as AuthConsolePolicy, q as AuthConsoleActivityQuery, rt as AuthConsoleFieldType, st as AuthConsoleMutation, tt as AuthConsoleField, ut as AuthConsoleOrganizationDetail, vt as AuthConsoleUser, xt as authConsoleActionNames, yt as AuthConsoleUserDetail } from "./types-BP9_XUr9.js";
2
+ import { i as describeAuthConsoleFields, n as AuthConsoleErrorCode, r as createAuthConsole, t as AuthConsole } from "./console-runtime-DAjLTLrN.js";
3
+ export { AuthConsole, type AuthConsoleAction, type AuthConsoleActivity, type AuthConsoleActivityQuery, type AuthConsoleAgent, type AuthConsoleCapability, type AuthConsoleColumn, type AuthConsoleDescription, AuthConsoleErrorCode, type AuthConsoleEvent, type AuthConsoleEventGroup, type AuthConsoleEventUser, type AuthConsoleField, type AuthConsoleFieldPolicy, type AuthConsoleFieldType, type AuthConsoleHostOptions, type AuthConsoleImpersonation, type AuthConsoleList, type AuthConsoleMutation, type AuthConsoleOptions, type AuthConsoleOrganization, type AuthConsoleOrganizationDetail, type AuthConsoleOverview, type AuthConsolePage, type AuthConsolePolicy, type AuthConsoleQuery, type AuthConsoleRoles, type AuthConsoleSession, type AuthConsoleSessionUser, type AuthConsoleUser, type AuthConsoleUserDetail, type AuthConsoleValue, type authConsoleActionNames, type authConsoleEventGroups, createAuthConsole, describeAuthConsoleFields };
@@ -1,2 +1 @@
1
- import { n as describeAuthConsoleFields, t as createAuthConsole } from "./console-runtime-CuXRDhGy.js";
2
- export { createAuthConsole, describeAuthConsoleFields };
1
+ export { t as createAuthConsole, n as describeAuthConsoleFields } from "./console-runtime-CaIXVtB_.js";
@@ -1,10 +1,11 @@
1
- //#region src/console-types.ts
1
+ // src/console-types.ts
2
2
  const authConsoleEventGroups = {
3
3
  "sign-in": [
4
4
  "user.signed_up",
5
5
  "user.signed_in",
6
6
  "user.signed_out",
7
- "sign_in.failed"
7
+ "sign_in.failed",
8
+ "session.expired"
8
9
  ],
9
10
  admin: [
10
11
  "session.revoked",
@@ -34,5 +35,4 @@ const authConsoleActionNames = [
34
35
  "impersonate",
35
36
  "revokeConsent"
36
37
  ];
37
- //#endregion
38
38
  export { authConsoleEventGroups as n, authConsoleActionNames as t };
package/dist/console.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { $ as AuthConsoleEventGroup, Ct as authConsoleActionNames, G as AuthConsoleAction, J as AuthConsoleAgent, K as AuthConsoleActivity, Q as AuthConsoleEvent, St as AuthConsoleValue, X as AuthConsoleColumn, Y as AuthConsoleCapability, Z as AuthConsoleDescription, _t as AuthConsoleRoles, at as AuthConsoleHostSession, bt as AuthConsoleUser, ct as AuthConsoleList, dt as AuthConsoleOrganization, et as AuthConsoleEventUser, ft as AuthConsoleOrganizationDetail, gt as AuthConsoleQuery, ht as AuthConsolePolicy, it as AuthConsoleHostOptions, lt as AuthConsoleMutation, mt as AuthConsolePage, nt as AuthConsoleFieldPolicy, ot as AuthConsoleHostUserInput, pt as AuthConsoleOverview, q as AuthConsoleActivityQuery, rt as AuthConsoleFieldType, st as AuthConsoleImpersonation, tt as AuthConsoleField, ut as AuthConsoleOptions, vt as AuthConsoleSession, wt as authConsoleEventGroups, xt as AuthConsoleUserDetail, yt as AuthConsoleSessionUser } from "./types-gl-myjZc.js";
2
- //#region ../internal/src/console.d.ts
1
+ import { $ as AuthConsoleEventGroup, G as AuthConsoleAction, J as AuthConsoleAgent, K as AuthConsoleActivity, Q as AuthConsoleEvent, St as authConsoleEventGroups, X as AuthConsoleColumn, Y as AuthConsoleCapability, Z as AuthConsoleDescription, _t as AuthConsoleSessionUser, at as AuthConsoleImpersonation, bt as AuthConsoleValue, ct as AuthConsoleOptions, dt as AuthConsoleOverview, et as AuthConsoleEventUser, ft as AuthConsolePage, gt as AuthConsoleSession, ht as AuthConsoleRoles, it as AuthConsoleHostOptions, lt as AuthConsoleOrganization, mt as AuthConsoleQuery, nt as AuthConsoleFieldPolicy, ot as AuthConsoleList, pt as AuthConsolePolicy, q as AuthConsoleActivityQuery, rt as AuthConsoleFieldType, st as AuthConsoleMutation, tt as AuthConsoleField, ut as AuthConsoleOrganizationDetail, vt as AuthConsoleUser, xt as authConsoleActionNames, yt as AuthConsoleUserDetail } from "./types-BP9_XUr9.js";
3
2
  /** Lists discovered Definitions in a sidebar and shows the selected Definition's fields. */
4
3
  interface ViteHubConsoleDefinitionCatalogView {
5
4
  kind: "definition-catalog";
@@ -67,7 +66,7 @@ interface ViteHubConsoleOperationAction {
67
66
  operation: string;
68
67
  input: Readonly<Record<string, string>>;
69
68
  /**
70
- * The result is `{ url }`, such as a one-time link or a provider sign-in: the Console opens it in a new tab, and loads
69
+ * The result is `{ url }`, such as a provider sign-in: the Console opens it in a new tab, and loads
71
70
  * the list again when the person comes back. The URL must be `https:`, or `http:` on a loopback host.
72
71
  */
73
72
  tab?: true;
@@ -211,9 +210,6 @@ interface ViteHubConsoleSectionDescriptor<TView extends ViteHubConsoleSectionVie
211
210
  /** Pages next to the main view, in sidebar order. Only document editor sections render pages today. */
212
211
  pages?: readonly ViteHubConsoleSectionPage[];
213
212
  }
214
- //#endregion
215
- //#region src/console.d.ts
216
213
  /** The owner descriptor. The host supplies the navigation and renders the Auth views. */
217
214
  export declare const authConsoleSection: ViteHubConsoleAuthSection;
218
- //#endregion
219
- export { type AuthConsoleAction, type AuthConsoleActivity, type AuthConsoleActivityQuery, type AuthConsoleAgent, type AuthConsoleCapability, type AuthConsoleColumn, type AuthConsoleDescription, type AuthConsoleEvent, type AuthConsoleEventGroup, type AuthConsoleEventUser, type AuthConsoleField, type AuthConsoleFieldPolicy, type AuthConsoleFieldType, type AuthConsoleHostOptions, type AuthConsoleHostSession, type AuthConsoleHostUserInput, type AuthConsoleImpersonation, type AuthConsoleList, type AuthConsoleMutation, type AuthConsoleOptions, type AuthConsoleOrganization, type AuthConsoleOrganizationDetail, type AuthConsoleOverview, type AuthConsolePage, type AuthConsolePolicy, type AuthConsoleQuery, type AuthConsoleRoles, type AuthConsoleSession, type AuthConsoleSessionUser, type AuthConsoleUser, type AuthConsoleUserDetail, type AuthConsoleValue, type authConsoleActionNames, authConsoleEventGroups };
215
+ export { type AuthConsoleAction, type AuthConsoleActivity, type AuthConsoleActivityQuery, type AuthConsoleAgent, type AuthConsoleCapability, type AuthConsoleColumn, type AuthConsoleDescription, type AuthConsoleEvent, type AuthConsoleEventGroup, type AuthConsoleEventUser, type AuthConsoleField, type AuthConsoleFieldPolicy, type AuthConsoleFieldType, type AuthConsoleHostOptions, type AuthConsoleImpersonation, type AuthConsoleList, type AuthConsoleMutation, type AuthConsoleOptions, type AuthConsoleOrganization, type AuthConsoleOrganizationDetail, type AuthConsoleOverview, type AuthConsolePage, type AuthConsolePolicy, type AuthConsoleQuery, type AuthConsoleRoles, type AuthConsoleSession, type AuthConsoleSessionUser, type AuthConsoleUser, type AuthConsoleUserDetail, type AuthConsoleValue, type authConsoleActionNames, authConsoleEventGroups };
package/dist/console.js CHANGED
@@ -1,5 +1,5 @@
1
- import { n as authConsoleEventGroups } from "./console-types-CmmnKGMx.js";
2
- //#region src/console.ts
1
+ import { n as authConsoleEventGroups } from "./console-types-NrX5TWl3.js";
2
+ // src/console.ts
3
3
  /** The owner descriptor. The host supplies the navigation and renders the Auth views. */
4
4
  const authConsoleSection = {
5
5
  id: "auth",
@@ -11,5 +11,4 @@ const authConsoleSection = {
11
11
  notice: "Better Auth owns user data and runs each change through its APIs."
12
12
  }
13
13
  };
14
- //#endregion
15
14
  export { authConsoleEventGroups, authConsoleSection };
@@ -1,5 +1,5 @@
1
- import { t as authErrorDiagnostics } from "./error-diagnostics-uEbxSY2G.js";
2
- //#region src/database-options.ts
1
+ import { t as authErrorDiagnostics } from "./error-diagnostics-CUPwukgE.js";
2
+ // src/database-options.ts
3
3
  /** Reads the adapter's target without loading Better Auth or the Database runtime. */
4
4
  function authDatabaseName(database) {
5
5
  if (typeof database !== "function") return;
@@ -25,5 +25,4 @@ function authDatabasePlacementError() {
25
25
  function authMemoryDatabaseError() {
26
26
  return authErrorDiagnostics.AUTH_C0063({ message: "`defineAuth()` has no `database` or `preset`. Auth keeps users and sessions in memory only on a development server, because a restart or a second instance loses them." });
27
27
  }
28
- //#endregion
29
28
  export { authDatabaseSchemaError as a, authDatabasePlacementError as i, authDatabaseAdditionalFieldsError as n, authMemoryDatabaseError as o, authDatabaseName as r, assertAuthDatabaseIdStrategy as t };
@@ -1,6 +1,6 @@
1
- import { a as authDatabaseSchemaError } from "./database-options-CcjUG-us.js";
1
+ import { a as authDatabaseSchemaError } from "./database-options-B87hDU4j.js";
2
2
  import { getAuthTables } from "better-auth/db";
3
- //#region src/database-schema-options.ts
3
+ // src/database-schema-options.ts
4
4
  /** Better Auth reads each table by its key and each column by its field key, so the options must not rename them. */
5
5
  function assertAuthDatabaseNames(options) {
6
6
  for (const [model, table] of Object.entries(getAuthTables(options))) {
@@ -8,5 +8,4 @@ function assertAuthDatabaseNames(options) {
8
8
  for (const [key, field] of Object.entries(table.fields)) if (field.fieldName && field.fieldName !== key) throw authDatabaseSchemaError(`${model}.${key} cannot map to ${JSON.stringify(field.fieldName)}, because the column keeps the key \`${key}\``);
9
9
  }
10
10
  }
11
- //#endregion
12
11
  export { assertAuthDatabaseNames as t };
@@ -1,12 +1,10 @@
1
- import { f as AuthAppDatabase } from "./types-gl-myjZc.js";
2
- //#region src/database.d.ts
1
+ import { f as AuthAppDatabase } from "./types-BP9_XUr9.js";
3
2
  /**
4
3
  * The Better Auth `database` adapter for the app Database `name` (default `"default"`). Pass it inline as the
5
- * `database` of `defineAuth()`. Auth then adds the Better Auth tables, with the fields of `admin()`, the
4
+ * `database` of `defineAuth()`. Auth then adds the Better Auth tables, the fields of `admin()` when the Definition calls it, the
6
5
  * Console MCP OAuth tables, the table of Better Auth's limiter, the `additionalFields` of the Definition, and the tables of
7
6
  * the plugins that it calls, such as `twoFactor()` and `apiKey()`, to that Database. The adapter uses the Database of each
8
7
  * request: SQLite, libSQL, Cloudflare D1, or Postgres.
9
8
  */
10
9
  export declare function authDatabase(name?: string): AuthAppDatabase;
11
- //#endregion
12
10
  export type { AuthAppDatabase };
package/dist/database.js CHANGED
@@ -1,18 +1,18 @@
1
- import { t as authErrorDiagnostics } from "./error-diagnostics-uEbxSY2G.js";
2
- import { a as authDatabaseSchemaError, t as assertAuthDatabaseIdStrategy } from "./database-options-CcjUG-us.js";
3
- import { t as assertAuthDatabaseNames } from "./database-schema-options-CTKCAfqW.js";
1
+ import { t as authErrorDiagnostics } from "./error-diagnostics-CUPwukgE.js";
2
+ import { a as authDatabaseSchemaError, t as assertAuthDatabaseIdStrategy } from "./database-options-B87hDU4j.js";
3
+ import { t as assertAuthDatabaseNames } from "./database-schema-options-peXHNLkJ.js";
4
4
  import { getAuthTables } from "better-auth/db";
5
5
  import { getTableColumns, is, isTable } from "drizzle-orm";
6
6
  import { drizzleAdapter } from "better-auth/adapters/drizzle";
7
7
  import { databases } from "@vite-hub/database/runtime/registry";
8
8
  import { PgAsyncDatabase } from "drizzle-orm/pg-core";
9
- //#region src/database.ts
9
+ // src/database.ts
10
10
  /**
11
11
  * Compares the tables and fields that the options need, with the plugins and additional fields, against the Drizzle
12
12
  * tables of the Database, before the adapter opens it.
13
13
  */
14
14
  function assertAuthDatabaseSchema(options, schema, database) {
15
- const fix = "Call the plugin in `server/auth.ts`, or in a file that it imports with a relative path, and write `additionalFields` inline in `server/auth.ts`, so that the Auth Vite plugin adds the columns. Then run `vitehub database generate` and apply the migration";
15
+ const fix = "Import the plugin by name from its package, such as `import { admin } from \"better-auth/plugins\"`, and call it in `server/auth.ts` or in a file that it imports with a relative path. Auth does not read a default import of the plugin, or a namespace that a local file re-exports. Write `additionalFields` inline in `server/auth.ts`, so that the Auth Vite plugin adds the columns. Then run `vitehub database generate` and apply the migration";
16
16
  for (const [model, table] of Object.entries(getAuthTables(options))) {
17
17
  const drizzleTable = Object.hasOwn(schema, model) ? schema[model] : void 0;
18
18
  if (!isTable(drizzleTable)) throw authDatabaseSchemaError(`the ${JSON.stringify(database)} Database has no \`${model}\` table. ${fix}`);
@@ -22,7 +22,7 @@ function assertAuthDatabaseSchema(options, schema, database) {
22
22
  }
23
23
  /**
24
24
  * The Better Auth `database` adapter for the app Database `name` (default `"default"`). Pass it inline as the
25
- * `database` of `defineAuth()`. Auth then adds the Better Auth tables, with the fields of `admin()`, the
25
+ * `database` of `defineAuth()`. Auth then adds the Better Auth tables, the fields of `admin()` when the Definition calls it, the
26
26
  * Console MCP OAuth tables, the table of Better Auth's limiter, the `additionalFields` of the Definition, and the tables of
27
27
  * the plugins that it calls, such as `twoFactor()` and `apiKey()`, to that Database. The adapter uses the Database of each
28
28
  * request: SQLite, libSQL, Cloudflare D1, or Postgres.
@@ -41,5 +41,4 @@ function authDatabase(name = "default") {
41
41
  };
42
42
  return Object.assign(adapter, { vitehubDatabase: name });
43
43
  }
44
- //#endregion
45
44
  export { authDatabase };
@@ -1,10 +1,10 @@
1
- import { t as authErrorDiagnostics } from "./error-diagnostics-uEbxSY2G.js";
2
- import { t as isRecord } from "./object-Da1zyPCR.js";
3
- import { t as accessRouteSyntaxError } from "./application-path-DuTpfGFj.js";
4
- import { a as normalizeAuthBasePath, n as assertAuthPages } from "./access-pages-FNQTyGRD.js";
5
- import { r as authDatabaseName } from "./database-options-CcjUG-us.js";
1
+ import { a as normalizeAuthBasePath, n as assertAuthPages } from "./access-pages-9aKr6z-k.js";
2
+ import { t as accessRouteSyntaxError } from "./application-path-zKi7NrvK.js";
3
+ import { t as authErrorDiagnostics } from "./error-diagnostics-CUPwukgE.js";
4
+ import { t as isRecord } from "./object-CAK6UYR5.js";
5
+ import { r as authDatabaseName } from "./database-options-B87hDU4j.js";
6
6
  import { parseDuration } from "@vite-hub/runtime";
7
- //#region src/stateless-user-id.ts
7
+ // src/stateless-user-id.ts
8
8
  const pendingUserIds = /* @__PURE__ */ new WeakMap();
9
9
  /** The user ID of one provider account: the first 32 hex digits of SHA-256 over the provider ID and the account ID. */
10
10
  async function statelessUserId(providerId, accountId) {
@@ -73,8 +73,7 @@ function withStatelessUserId(options) {
73
73
  }
74
74
  };
75
75
  }
76
- //#endregion
77
- //#region src/preset-options.ts
76
+ // src/preset-options.ts
78
77
  const verificationPluginIds = /* @__PURE__ */ new Set([
79
78
  "email-otp",
80
79
  "magic-link",
@@ -165,8 +164,7 @@ function applyAuthPreset(options) {
165
164
  const { preset, ...rest } = options;
166
165
  return applyStatelessPreset(readStatelessPreset(preset), rest);
167
166
  }
168
- //#endregion
169
- //#region src/events-config.ts
167
+ // src/events-config.ts
170
168
  function validateAuthEvents(value) {
171
169
  if (value === void 0 || value === false) return;
172
170
  if (!value || typeof value !== "object" || !("store" in value) || !value.store || typeof value.store !== "object" || ![
@@ -175,16 +173,14 @@ function validateAuthEvents(value) {
175
173
  "aggregate"
176
174
  ].every((key) => typeof Reflect.get(value.store, key) === "function") || "authorize" in value && value.authorize !== void 0 && typeof value.authorize !== "function" || "onEvent" in value && value.onEvent !== void 0 && typeof value.onEvent !== "function") throw authErrorDiagnostics.AUTH_C0050({ message: "`defineAuth()` events needs a store with append, list, and aggregate methods. events.authorize and events.onEvent must be functions. Set events to false to disable the log." });
177
175
  }
178
- //#endregion
179
- //#region ../internal/src/runtime/user-data.ts
176
+ // ../internal/src/runtime/user-data.ts
180
177
  const stateKey = Symbol.for("vitehub.user-data");
181
178
  const scope = globalThis;
182
179
  /** The registered owners, by owner name. */
183
180
  function viteHubUserData(app) {
184
181
  return [...(app && scope[stateKey]?.get(app))?.values() ?? []].sort((left, right) => left.owner.localeCompare(right.owner));
185
182
  }
186
- //#endregion
187
- //#region src/delete-account.ts
183
+ // src/delete-account.ts
188
184
  /** Also checked when a Definition callback returns the options. */
189
185
  function validateDeleteAccount(options) {
190
186
  if (isRecord(options.user) && options.user.deleteUser !== void 0) throw authErrorDiagnostics.AUTH_DELETE_USER_UNSUPPORTED();
@@ -302,8 +298,7 @@ function createDeleteAccount(option, app) {
302
298
  }
303
299
  };
304
300
  }
305
- //#endregion
306
- //#region src/definition.ts
301
+ // src/definition.ts
307
302
  const authRuntimeOptionNames = /* @__PURE__ */ new Set([
308
303
  "baseURL",
309
304
  "secret",
@@ -422,5 +417,4 @@ function defineAuthOptions(options) {
422
417
  applyAuthPreset(options);
423
418
  return { options };
424
419
  }
425
- //#endregion
426
420
  export { createDeleteAccount as a, applyAuthPreset as c, validateAuthComponents as i, defineAuth as n, validateDeleteAccount as o, validateAuthAccessPolicy as r, validateAuthEvents as s, assertNoRuntimeOption as t };
@@ -1,5 +1,5 @@
1
1
  import { defineDiagnostics } from "nostics";
2
- //#region src/error-diagnostics.ts
2
+ // src/error-diagnostics.ts
3
3
  const dynamicError = { why: ({ message }) => message === void 0 ? "" : String(message) };
4
4
  /** A code whose call site passes the message as `why`, with the fix that the reader applies. */
5
5
  const withFix = (fix) => ({
@@ -122,7 +122,7 @@ const authErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
122
122
  AUTH_C0053: withFix("Remove `advanced.database.generateId`, or set it to a function that returns strings. Use another Better Auth adapter for numeric or UUID IDs."),
123
123
  AUTH_C0054: withFix("Call `authDatabase()` inline as `database` in the object of `defineAuth()`, or in the one object that its callback returns. Do not select it in a branch."),
124
124
  AUTH_C0055: withFix("Write `additionalFields` inline in `server/auth.ts`, with a literal `type` for each field, for example `user: { additionalFields: { login: { type: 'string', required: false } } }`."),
125
- AUTH_C0056: withFix("Remove the `modelName` or `fieldName` change. For a plugin that adds a table or a column, call it in `server/auth.ts` or in a file that `server/auth.ts` imports with a relative path, so that the Auth Vite plugin adds its tables, or add its tables to the Database Definition. Then run `vitehub database generate`."),
125
+ AUTH_C0056: withFix("Remove the `modelName` or `fieldName` change. For a plugin that adds a table or a column, import it by name from its package, such as `import { admin } from 'better-auth/plugins'`, and call it in `server/auth.ts` or in a file that `server/auth.ts` imports with a relative path, so that the Auth Vite plugin adds its tables, or add its tables to the Database Definition. Then run `vitehub database generate`."),
126
126
  AUTH_C0057: withFix("Unset `VITEHUB_ADMIN_EMAILS`. List each admin's social account in `VITEHUB_ADMINS`, for example `VITEHUB_ADMINS=github:22072217`."),
127
127
  AUTH_C0058: withFix("Write each `VITEHUB_ADMINS` entry as `<provider>:<account id>`, for example `github:22072217`. Run `gh api users/<login> --jq .id` to get a GitHub account id. For an app with only email sign-in, remove `VITEHUB_ADMINS`, then run `vitehub auth claim`."),
128
128
  AUTH_C0059: withFix("Run `vitehub auth claim` and set `VITEHUB_ADMIN_CLAIM` to the `sha256:` value that it prints. Do not set the code itself."),
@@ -176,5 +176,4 @@ const authErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
176
176
  }
177
177
  }
178
178
  });
179
- //#endregion
180
179
  export { authErrorDiagnostics as t };
@@ -1,9 +1,9 @@
1
- import { t as authErrorDiagnostics } from "./error-diagnostics-uEbxSY2G.js";
2
- import { t as isRecord } from "./object-Da1zyPCR.js";
1
+ import { t as authErrorDiagnostics } from "./error-diagnostics-CUPwukgE.js";
2
+ import { t as isRecord } from "./object-CAK6UYR5.js";
3
3
  import { defineErrors } from "@vite-hub/runtime";
4
4
  import { sql } from "drizzle-orm";
5
5
  import * as v from "valibot";
6
- //#region src/github.ts
6
+ // src/github.ts
7
7
  const githubErrors = /*#__PURE__*/ defineErrors({
8
8
  docs: "https://vitehub.dev/docs/auth/diagnostics",
9
9
  codes: {
@@ -108,14 +108,14 @@ async function checkGitHubOrgMember(accessToken, org, options = {}) {
108
108
  }
109
109
  return result;
110
110
  }
111
- //#endregion
112
- //#region src/events.ts
111
+ // src/events.ts
113
112
  const authEventTypes = [
114
113
  "user.signed_up",
115
114
  "user.signed_in",
116
115
  "user.signed_out",
117
116
  "sign_in.failed",
118
117
  "session.revoked",
118
+ "session.expired",
119
119
  "user.banned",
120
120
  "user.unbanned",
121
121
  "user.role_changed",
@@ -302,5 +302,4 @@ function createDatabaseAuthEventStore(options) {
302
302
  }
303
303
  };
304
304
  }
305
- //#endregion
306
305
  export { checkGitHubOrgMember as a, parseAuthEventWindow as i, defaultAuthEventRetention as n, parseAuthEventList as r, createDatabaseAuthEventStore as t };
@@ -0,0 +1,4 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ // src/forward-sign-ins.ts
3
+ const forwardSignIns = new AsyncLocalStorage();
4
+ export { forwardSignIns as t };