@vite-hub/auth 0.4.1 → 0.5.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 (89) hide show
  1. package/README.md +32 -8
  2. package/dist/{abilities-CbmTAoS_.d.ts → abilities-3L1Y5Pnw.d.ts} +2 -4
  3. package/dist/abilities.d.ts +1 -1
  4. package/dist/abilities.js +1 -2
  5. package/dist/{ability-error-IeZQBr_-.js → ability-error-BHhPkrZd.js} +3 -5
  6. package/dist/{ability-error-DcgChwCN.d.ts → ability-error-C1c30O6E.d.ts} +1 -5
  7. package/dist/access-pages-BwImVHN_.js +94 -0
  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-CmDogt4D.js → auth-instance-_J7R9Qs1.js} +239 -50
  13. package/dist/{cli-ubYJpAL_.d.ts → cli-C5pAfY4x.d.ts} +1 -6
  14. package/dist/cli.d.ts +2 -4
  15. package/dist/cli.js +3 -4
  16. package/dist/{console-runtime-D2ai-Et5.d.ts → console-runtime-BP1ZKJB0.d.ts} +13 -13
  17. package/dist/{console-runtime-_LrpyCYY.js → console-runtime-vc3JQEuq.js} +72 -40
  18. package/dist/console-runtime.d.ts +2 -2
  19. package/dist/console-runtime.js +1 -2
  20. package/dist/{console-types-CmmnKGMx.js → console-types-51lkf0lk.js} +1 -2
  21. package/dist/console.d.ts +1 -5
  22. package/dist/console.js +2 -3
  23. package/dist/{database-options-DpOVjUti.js → database-options-DQ-8qYMl.js} +2 -3
  24. package/dist/{database-schema-options-Sk-1Bvyu.js → database-schema-options-CkSeU9V3.js} +2 -3
  25. package/dist/database.d.ts +1 -3
  26. package/dist/database.js +5 -6
  27. package/dist/{definition-BCaLA9kW.js → definition-MDGMNKrK.js} +20 -18
  28. package/dist/{error-diagnostics-Dymr-S_n.js → error-diagnostics-BssJr_2t.js} +9 -4
  29. package/dist/{events-DCfuicoo.js → events-DZqMiae_.js} +4 -6
  30. package/dist/forward.d.ts +1 -3
  31. package/dist/forward.js +2 -3
  32. package/dist/index.d.ts +4 -7
  33. package/dist/index.js +4 -3
  34. package/dist/internal/server.d.ts +4 -4
  35. package/dist/internal/server.js +5 -5
  36. package/dist/{invariant-D8_xBqmZ.js → invariant-Dj2R1eMr.js} +2 -3
  37. package/dist/{mcp-config-DRRlCAWN.js → mcp-config-C7srUMIZ.js} +2 -3
  38. package/dist/{mcp-token-CpxLyl_p.js → mcp-token--KuLYEub.js} +7 -18
  39. package/dist/mcp.d.ts +0 -4
  40. package/dist/mcp.js +4 -5
  41. package/dist/{members-DdlsS8kJ.js → members-D3_Q5XJb.js} +10 -14
  42. package/dist/nitro-kit-Bg4xUZAI.js +43 -0
  43. package/dist/{nuxt-bridge-Cl988STZ.js → nuxt-bridge-pRyfYD5c.js} +1 -2
  44. package/dist/nuxt.d.ts +31 -24
  45. package/dist/nuxt.js +336 -18
  46. package/dist/{object-Da1zyPCR.js → object-CAK6UYR5.js} +1 -2
  47. package/dist/own-access-C22hSIuF.d.ts +18 -0
  48. package/dist/own-access-DQgqxTbI.js +30 -0
  49. package/dist/{page-tools-shared-l4eyj53D.js → page-tools-shared-CtoKaNQZ.js} +1 -2
  50. package/dist/{presets-CHndEv5i.d.ts → presets-C6AtiRdI.d.ts} +0 -2
  51. package/dist/presets.d.ts +1 -1
  52. package/dist/presets.js +2 -3
  53. package/dist/{request-z6DHHmrb.js → request-Dpq7GO8B.js} +2 -4
  54. package/dist/runtime/console.d.ts +1 -1
  55. package/dist/runtime/console.js +2 -2
  56. package/dist/runtime/empty-abilities.d.ts +1 -3
  57. package/dist/runtime/empty-abilities.js +1 -2
  58. package/dist/runtime/empty-client.d.ts +0 -2
  59. package/dist/runtime/empty-client.js +1 -2
  60. package/dist/runtime/empty-definition.d.ts +1 -3
  61. package/dist/runtime/empty-definition.js +1 -2
  62. package/dist/runtime/nuxt.d.ts +1 -3
  63. package/dist/runtime/nuxt.js +1 -2
  64. package/dist/runtime/server.d.ts +3 -2
  65. package/dist/runtime/server.js +27 -19
  66. package/dist/runtime/vue-nuxt.d.ts +0 -2
  67. package/dist/runtime/vue-nuxt.js +74 -33
  68. package/dist/{runtime-state-ojQCzKOc.js → runtime-state-DtKUfxKq.js} +1 -2
  69. package/dist/schema.d.ts +71 -23
  70. package/dist/schema.js +6 -5
  71. package/dist/{server-BM-RSf1T.d.ts → server-CFWlYQJb.d.ts} +7 -14
  72. package/dist/{server-BG_MFd4q.js → server-D4Hi4TBI.js} +51 -33
  73. package/dist/{server-C8TlOrSy.d.ts → server-DCsgxFPP.d.ts} +9 -14
  74. package/dist/server.d.ts +2 -2
  75. package/dist/server.js +2 -2
  76. package/dist/{session-cookies-DVzjOKc7.js → session-cookies-1FMcMnRh.js} +6 -8
  77. package/dist/{set-cookie-DmqWq6kj.js → set-cookie-DkqM1kvj.js} +3 -5
  78. package/dist/{table-specs-DbXyaXWs.d.ts → table-specs-BLm_Zlss.d.ts} +255 -3
  79. package/dist/{table-specs-CURphR3n.js → table-specs-jw0jjU6l.js} +43 -44
  80. package/dist/test.d.ts +2 -4
  81. package/dist/test.js +3 -4
  82. package/dist/{types-CruflEFI.d.ts → types-BHSgxyvV.d.ts} +50 -11
  83. package/dist/{vite-Dy0Xhq4H.js → vite-D1xC9n1O.js} +365 -152
  84. package/dist/vite.d.ts +7 -14
  85. package/dist/vite.js +1 -2
  86. package/dist/vue.d.ts +17 -72
  87. package/dist/vue.js +25 -73
  88. package/package.json +35 -30
  89. package/dist/shared-DRtfuFsV.js +0 -12
@@ -1,19 +1,20 @@
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-DdlsS8kJ.js";
3
- import { r as isAuthProcessMemoryDatabase } from "./runtime-state-ojQCzKOc.js";
4
- import { r as parseAuthEventList } from "./events-DCfuicoo.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-D3_Q5XJb.js";
2
+ import { n as adminClaimVariable } from "./admin-claim-code-C3X_U43x.js";
3
+ import { n as authConsoleEventGroups, t as authConsoleActionNames } from "./console-types-51lkf0lk.js";
4
+ import { r as parseAuthEventList } from "./events-DZqMiae_.js";
5
+ import { r as isAuthProcessMemoryDatabase } from "./runtime-state-DtKUfxKq.js";
6
6
  import { defineErrors } from "@vite-hub/runtime";
7
7
  import { createAuthEndpoint } from "better-auth/api";
8
8
  import { setSessionCookie } from "better-auth/cookies";
9
+ import { getAuthTables } from "better-auth/db";
9
10
  import { defineGrant } from "@vite-hub/runtime/internal/grant";
10
- //#region ../internal/src/runtime/user-agent.ts
11
+ // ../internal/src/runtime/user-agent.ts
11
12
  /** A short device label of a browser, such as `Chrome · macOS`, for lists of sessions. It never shows the user agent itself. */
12
13
  function userAgentDevice(userAgent) {
13
14
  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"}`;
14
15
  }
15
- //#endregion
16
- //#region src/console-runtime.ts
16
+ // src/console-runtime.ts
17
+ const hostGuestProvider = "vitehub-site-guest";
17
18
  const string = (value) => typeof value === "string" ? value : "";
18
19
  const date = (value) => {
19
20
  const parsed = value instanceof Date ? value : new Date(typeof value === "string" || typeof value === "number" ? value : NaN);
@@ -101,8 +102,8 @@ const errors = defineErrors({
101
102
  fix: "Refresh the list and check the Auth Definition's plugins."
102
103
  },
103
104
  AUTH_CONSOLE_UNAVAILABLE: {
104
- why: ({ detail }) => detail ?? "Auth does not have the database or plugin API needed for this operation.",
105
- fix: "Configure a database adapter and the required Better Auth plugin."
105
+ why: ({ detail }) => detail ?? "Auth does not have the database, the `user.role` field, or the Better Auth plugin API that this operation needs.",
106
+ 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`."
106
107
  },
107
108
  AUTH_CONSOLE_PROVIDER_FAILED: {
108
109
  why: "Better Auth or an app column reader could not complete the operation.",
@@ -976,11 +977,14 @@ function createAuthConsole(auth, policy = {}, events, host = {}) {
976
977
  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.");
977
978
  return ctx.internalAdapter;
978
979
  }
979
- /** The Better Auth context for host users and sessions: `admin()` keeps the roles, a database keeps the rest. */
980
+ /** The Better Auth context for host users and sessions: the `user.role` field keeps the roles, a database keeps the rest. */
980
981
  async function hostContext() {
981
982
  const ctx = await context();
982
983
  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.");
983
- if (!ctx.options.plugins?.some((plugin) => plugin.id === "admin")) throw authConsoleError(409, "Site access keeps permissions as roles of Better Auth's admin() plugin. Add admin() from better-auth/plugins to the plugins of defineAuth().");
984
+ const role = getAuthTables(ctx.options).user?.fields.role;
985
+ 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 } } }`.");
986
+ 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()`.");
987
+ 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.");
984
988
  return {
985
989
  ...ctx,
986
990
  internalAdapter: ctx.internalAdapter,
@@ -989,6 +993,22 @@ function createAuthConsole(auth, policy = {}, events, host = {}) {
989
993
  sessionConfig: ctx.sessionConfig
990
994
  };
991
995
  }
996
+ async function isHostGuest(userId) {
997
+ return Boolean(await find("account", [
998
+ {
999
+ field: "providerId",
1000
+ value: hostGuestProvider
1001
+ },
1002
+ {
1003
+ field: "accountId",
1004
+ value: userId
1005
+ },
1006
+ {
1007
+ field: "userId",
1008
+ value: userId
1009
+ }
1010
+ ]));
1011
+ }
992
1012
  async function hostUser(input) {
993
1013
  const ctx = await hostContext();
994
1014
  const email = input.email?.trim().toLowerCase();
@@ -1005,14 +1025,20 @@ function createAuthConsole(auth, policy = {}, events, host = {}) {
1005
1025
  };
1006
1026
  }
1007
1027
  const roles = [...new Set(input.roles)];
1028
+ const user = await ctx.internalAdapter.createUser({
1029
+ email: email || `guest-${crypto.randomUUID()}@guests.invalid`,
1030
+ emailVerified: Boolean(email),
1031
+ name: input.name,
1032
+ ...input.image ? { image: input.image } : {},
1033
+ role: roles.join(",")
1034
+ }, { method: "admin" });
1035
+ if (!email && !await ctx.internalAdapter.createAccount({
1036
+ providerId: hostGuestProvider,
1037
+ accountId: user.id,
1038
+ userId: user.id
1039
+ })) throw authConsoleError(409, "Better Auth did not store the Site access guest account.");
1008
1040
  return {
1009
- id: (await ctx.internalAdapter.createUser({
1010
- email: email || `guest-${crypto.randomUUID()}@guests.invalid`,
1011
- emailVerified: Boolean(email),
1012
- name: input.name,
1013
- ...input.image ? { image: input.image } : {},
1014
- role: roles.join(",")
1015
- }, { method: "admin" })).id,
1041
+ id: user.id,
1016
1042
  roles
1017
1043
  };
1018
1044
  }
@@ -1045,15 +1071,22 @@ function createAuthConsole(auth, policy = {}, events, host = {}) {
1045
1071
  limit: 1e3
1046
1072
  });
1047
1073
  const now = Date.now();
1048
- return (await Promise.all(holders.filter((user) => roleList(user.role).some((role) => roles.includes(role))).map(async (user) => (await storedSessions(string(user.id))).filter((session) => new Date(date(session.expiresAt)).getTime() > now).map((session) => ({
1049
- id: string(session.id),
1050
- user: userSummary(user),
1051
- roles: roleList(user.role),
1052
- device: userAgentDevice(string(session.userAgent)),
1053
- createdAt: date(session.createdAt),
1054
- updatedAt: date(session.updatedAt),
1055
- expiresAt: date(session.expiresAt)
1056
- }))))).flat().sort((left, right) => right.updatedAt.localeCompare(left.updatedAt));
1074
+ return (await Promise.all(holders.filter((user) => roleList(user.role).some((role) => roles.includes(role))).map(async (user) => {
1075
+ const userId = string(user.id);
1076
+ const userRoles = roleList(user.role);
1077
+ const guest = await isHostGuest(userId);
1078
+ if (!userRoles.some((role) => roles.includes(role) && (role !== "guest" || guest))) return [];
1079
+ return (await storedSessions(userId)).filter((session) => new Date(date(session.expiresAt)).getTime() > now).map((session) => ({
1080
+ id: string(session.id),
1081
+ user: userSummary(user),
1082
+ roles: userRoles,
1083
+ guest,
1084
+ device: userAgentDevice(string(session.userAgent)),
1085
+ createdAt: date(session.createdAt),
1086
+ updatedAt: date(session.updatedAt),
1087
+ expiresAt: date(session.expiresAt)
1088
+ }));
1089
+ }))).flat().sort((left, right) => right.updatedAt.localeCompare(left.updatedAt));
1057
1090
  }
1058
1091
  async function stopImpersonating(request) {
1059
1092
  if (host.bearer) throw authConsoleError(403, "Impersonation needs the browser's app session.");
@@ -1127,24 +1160,24 @@ function createAuthConsole(auth, policy = {}, events, host = {}) {
1127
1160
  await (await verifications()).deleteVerificationByIdentifier(identifier);
1128
1161
  }),
1129
1162
  hostUser: (input) => result(() => hostUser(input)),
1163
+ checkHost: () => result(async () => {
1164
+ await hostContext();
1165
+ }),
1130
1166
  hostSession: (userId, request) => result(() => hostSession(userId, request)),
1131
1167
  hostSessions: (roles) => result(() => hostSessions(roles)),
1132
1168
  revokeHostSession: (id) => result(async () => {
1133
1169
  const ctx = await hostContext();
1134
1170
  const session = await hostSessionById(id);
1135
1171
  if (!session) throw authConsoleError(404, "No session has this id. It ended, or someone revoked it.");
1172
+ const userId = string(session.userId);
1173
+ const guest = await isHostGuest(userId);
1136
1174
  await ctx.internalAdapter.deleteSession(string(session.token));
1137
- const owner = await find("user", equality("id", string(session.userId)));
1138
- return {
1139
- userId: string(session.userId),
1140
- roles: roleList(owner?.role)
1141
- };
1142
- }),
1143
- removeHostUser: (userId) => result(async () => {
1144
- const ctx = await hostContext();
1145
- await ctx.internalAdapter.deleteUserSessions(userId);
1146
- await ctx.internalAdapter.deleteAccounts(userId);
1147
- await ctx.internalAdapter.deleteUser(userId);
1175
+ if (guest) {
1176
+ await ctx.internalAdapter.deleteUserSessions(userId);
1177
+ await ctx.internalAdapter.deleteAccounts(userId);
1178
+ await ctx.internalAdapter.deleteUser(userId);
1179
+ }
1180
+ return { removedUser: guest };
1148
1181
  })
1149
1182
  };
1150
1183
  }
@@ -1162,5 +1195,4 @@ async function signedSessionToken(secret, token) {
1162
1195
  function roleList(value) {
1163
1196
  return string(value).split(",").map((role) => role.trim()).filter(Boolean);
1164
1197
  }
1165
- //#endregion
1166
1198
  export { describeAuthConsoleFields as n, createAuthConsole as t };
@@ -1,3 +1,3 @@
1
- import { $ as AuthConsoleEventUser, Ct as authConsoleEventGroups, G as AuthConsoleActivity, J as AuthConsoleCapability, K as AuthConsoleActivityQuery, Q as AuthConsoleEventGroup, St as authConsoleActionNames, W as AuthConsoleAction, X as AuthConsoleDescription, Y as AuthConsoleColumn, Z as AuthConsoleEvent, _t as AuthConsoleSession, at as AuthConsoleHostUserInput, bt as AuthConsoleUserDetail, ct as AuthConsoleMutation, dt as AuthConsoleOrganizationDetail, et as AuthConsoleField, ft as AuthConsoleOverview, gt as AuthConsoleRoles, ht as AuthConsoleQuery, it as AuthConsoleHostSession, lt as AuthConsoleOptions, mt as AuthConsolePolicy, nt as AuthConsoleFieldType, ot as AuthConsoleImpersonation, pt as AuthConsolePage, q as AuthConsoleAgent, rt as AuthConsoleHostOptions, st as AuthConsoleList, tt as AuthConsoleFieldPolicy, ut as AuthConsoleOrganization, vt as AuthConsoleSessionUser, xt as AuthConsoleValue, yt as AuthConsoleUser } from "./types-CruflEFI.js";
2
- import { i as describeAuthConsoleFields, n as AuthConsoleErrorCode, r as createAuthConsole, t as AuthConsole } from "./console-runtime-D2ai-Et5.js";
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-BHSgxyvV.js";
2
+ import { i as describeAuthConsoleFields, n as AuthConsoleErrorCode, r as createAuthConsole, t as AuthConsole } from "./console-runtime-BP1ZKJB0.js";
3
3
  export { AuthConsole, type AuthConsoleAction, type AuthConsoleActivity, type AuthConsoleActivityQuery, type AuthConsoleAgent, type AuthConsoleCapability, type AuthConsoleColumn, type AuthConsoleDescription, AuthConsoleErrorCode, type AuthConsoleEvent, type AuthConsoleEventGroup, type AuthConsoleEventUser, type AuthConsoleField, type AuthConsoleFieldPolicy, type AuthConsoleFieldType, type AuthConsoleHostOptions, type 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,2 +1 @@
1
- import { n as describeAuthConsoleFields, t as createAuthConsole } from "./console-runtime-_LrpyCYY.js";
2
- export { createAuthConsole, describeAuthConsoleFields };
1
+ export { t as createAuthConsole, n as describeAuthConsoleFields } from "./console-runtime-vc3JQEuq.js";
@@ -1,4 +1,4 @@
1
- //#region src/console-types.ts
1
+ // src/console-types.ts
2
2
  const authConsoleEventGroups = {
3
3
  "sign-in": [
4
4
  "user.signed_up",
@@ -34,5 +34,4 @@ const authConsoleActionNames = [
34
34
  "impersonate",
35
35
  "revokeConsent"
36
36
  ];
37
- //#endregion
38
37
  export { authConsoleEventGroups as n, authConsoleActionNames as t };
package/dist/console.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { $ as AuthConsoleEventUser, Ct as authConsoleEventGroups, G as AuthConsoleActivity, J as AuthConsoleCapability, K as AuthConsoleActivityQuery, Q as AuthConsoleEventGroup, St as authConsoleActionNames, W as AuthConsoleAction, X as AuthConsoleDescription, Y as AuthConsoleColumn, Z as AuthConsoleEvent, _t as AuthConsoleSession, at as AuthConsoleHostUserInput, bt as AuthConsoleUserDetail, ct as AuthConsoleMutation, dt as AuthConsoleOrganizationDetail, et as AuthConsoleField, ft as AuthConsoleOverview, gt as AuthConsoleRoles, ht as AuthConsoleQuery, it as AuthConsoleHostSession, lt as AuthConsoleOptions, mt as AuthConsolePolicy, nt as AuthConsoleFieldType, ot as AuthConsoleImpersonation, pt as AuthConsolePage, q as AuthConsoleAgent, rt as AuthConsoleHostOptions, st as AuthConsoleList, tt as AuthConsoleFieldPolicy, ut as AuthConsoleOrganization, vt as AuthConsoleSessionUser, xt as AuthConsoleValue, yt as AuthConsoleUser } from "./types-CruflEFI.js";
2
- //#region ../internal/src/console.d.ts
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-BHSgxyvV.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";
@@ -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
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 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 };
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-51lkf0lk.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-Dymr-S_n.js";
2
- //#region src/database-options.ts
1
+ import { t as authErrorDiagnostics } from "./error-diagnostics-BssJr_2t.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-DpOVjUti.js";
1
+ import { a as authDatabaseSchemaError } from "./database-options-DQ-8qYMl.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,5 +1,4 @@
1
- import { f as AuthAppDatabase } from "./types-CruflEFI.js";
2
- //#region src/database.d.ts
1
+ import { f as AuthAppDatabase } from "./types-BHSgxyvV.js";
3
2
  /**
4
3
  * The Better Auth `database` adapter for the app Database `name` (default `"default"`). Pass it inline as the
5
4
  * `database` of `defineAuth()`. Auth then adds the Better Auth tables, with the fields of `admin()`, the
@@ -8,5 +7,4 @@ import { f as AuthAppDatabase } from "./types-CruflEFI.js";
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-Dymr-S_n.js";
2
- import { a as authDatabaseSchemaError, t as assertAuthDatabaseIdStrategy } from "./database-options-DpOVjUti.js";
3
- import { t as assertAuthDatabaseNames } from "./database-schema-options-Sk-1Bvyu.js";
1
+ import { t as authErrorDiagnostics } from "./error-diagnostics-BssJr_2t.js";
2
+ import { a as authDatabaseSchemaError, t as assertAuthDatabaseIdStrategy } from "./database-options-DQ-8qYMl.js";
3
+ import { t as assertAuthDatabaseNames } from "./database-schema-options-CkSeU9V3.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` and write `additionalFields` inline there, so that the Auth Vite plugin adds the columns. Then run `vitehub database generate` and apply the migration";
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";
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}`);
@@ -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-Dymr-S_n.js";
2
- import { t as isRecord } from "./object-Da1zyPCR.js";
3
- import { t as accessRouteSyntaxError } from "./application-path-DuTpfGFj.js";
4
- import { t as normalizeAuthBasePath } from "./shared-DRtfuFsV.js";
5
- import { r as authDatabaseName } from "./database-options-DpOVjUti.js";
1
+ import { a as normalizeAuthBasePath, n as assertAuthPages } from "./access-pages-BwImVHN_.js";
2
+ import { t as accessRouteSyntaxError } from "./application-path-zKi7NrvK.js";
3
+ import { t as authErrorDiagnostics } from "./error-diagnostics-BssJr_2t.js";
4
+ import { t as isRecord } from "./object-CAK6UYR5.js";
5
+ import { r as authDatabaseName } from "./database-options-DQ-8qYMl.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",
@@ -374,6 +369,13 @@ function validateAuthAccess(value) {
374
369
  validateAuthAccessPolicy(access.policy);
375
370
  validateAuthSignIn(access.signIn);
376
371
  if (typeof access.afterSignIn !== "undefined" && !isAppPath(access.afterSignIn)) throw authErrorDiagnostics.AUTH_AFTER_SIGN_IN_INVALID();
372
+ if (typeof access.pages !== "undefined") assertAuthPages(access.pages);
373
+ }
374
+ function validateAuthComponents(value) {
375
+ if (typeof value === "undefined") return;
376
+ if (!isRecord(value) || Object.keys(value).some((key) => key !== "prefix")) throw authErrorDiagnostics.AUTH_COMPONENTS_INVALID();
377
+ const prefix = value.prefix;
378
+ if (typeof prefix !== "undefined" && (typeof prefix !== "string" || !prefix.trim() || prefix !== prefix.trim())) throw authErrorDiagnostics.AUTH_COMPONENTS_INVALID();
377
379
  }
378
380
  /** A path of the app: one `/`, then no `/` or `\`, so it cannot name another site. */
379
381
  function isAppPath(value) {
@@ -411,8 +413,8 @@ function defineAuthOptions(options) {
411
413
  validateAuthDatabase(viteHubOptions.database);
412
414
  validateAuthSecondaryStorage(viteHubOptions.secondaryStorage);
413
415
  validateAuthAccess(viteHubOptions.access);
416
+ validateAuthComponents(viteHubOptions.components);
414
417
  applyAuthPreset(options);
415
418
  return { options };
416
419
  }
417
- //#endregion
418
- export { validateDeleteAccount as a, createDeleteAccount as i, defineAuth as n, validateAuthEvents as o, validateAuthAccessPolicy as r, applyAuthPreset as s, assertNoRuntimeOption as t };
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) => ({
@@ -57,6 +57,11 @@ const authErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
57
57
  why: "`defineAuth()` access.afterSignIn must be an inline path of the app that starts with one `/`.",
58
58
  fix: "Set `access.afterSignIn` to a string literal path, for example `afterSignIn: '/dashboard'`. The Nuxt page guard reads it at build time."
59
59
  },
60
+ AUTH_COMPONENTS_INVALID: {
61
+ why: "`defineAuth()` components must be an inline object with only `prefix`, an inline non-empty string.",
62
+ fix: "Write `components: { prefix: 'Custom' }` in `defineAuth()` to register `<CustomAuthPermission>`, or remove `components`. The Nuxt module reads the prefix at build time, so it cannot use a variable or an expression."
63
+ },
64
+ AUTH_PAGE_ROUTES_INVALID: withFix("Write `access.pages` inline in `defineAuth()`, and do not use a spread or a computed key in `access`. Start each key with `/` and use only static segments, `:name`, and a last `**`. Keep one key for the same pages, and set each value to `'user'`, `'guest'`, or `false`, for example `pages: { '/dashboard/**': 'user', '/login': 'guest' }`. For an optional segment, add one key with the segment and one key without it."),
60
65
  AUTH_REDIRECTS_MOVED: {
61
66
  why: "`vitehub({ auth })` takes only `true` or `false`. The `redirects` option moved to the Auth Definition.",
62
67
  fix: "Remove the object from `auth` in `vitehub()`. In `server/auth.ts`, set `access: { signIn: '/login', afterSignIn: '/' }`: `redirects.login` is now `signIn`, and `redirects.guest` is now `afterSignIn`. `vitehub migrate` moves them."
@@ -84,7 +89,7 @@ const authErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
84
89
  AUTH_C0012: withFix("Write `access.routes` as an array literal in `defineAuth()`, for example `access: { routes: ['/admin/**'] }`. The Vite plugin reads it at build time."),
85
90
  AUTH_C0014: withFix("Set `database: authDatabase()` with `import { authDatabase } from 'vite-hub/auth/database'`, or `authDatabase('auth')` for the Named Database `auth`. Return another Better Auth adapter from the Definition callback. Set `database: \"memory\"` to keep sessions in the memory of one server process."),
86
91
  AUTH_C0017: withFix("Remove `secondaryStorage` from the static options. Return a Better Auth `secondaryStorage` adapter, an object with `get`, `set`, and `delete`, from the Definition callback."),
87
- AUTH_C0019: withFix("Pass an object literal to `defineAuth()` in `server/auth.ts`, or a callback that returns one, for example `export default defineAuth({ basePath: '/auth' })`. Do not pass a variable."),
92
+ AUTH_C0019: withFix("Pass an object literal to `defineAuth()` in `server/auth.ts`, or a callback that returns one, for example `export default defineAuth({ basePath: '/auth' })`. Do not pass a variable. Export the call, or a top-level `const` that holds it."),
88
93
  AUTH_C0021: withFix("Set `database: authDatabase()` with `import { authDatabase } from 'vite-hub/auth/database'`, or `authDatabase('auth')` for the Named Database `auth`. Return another Better Auth adapter from the Definition callback. Set `database: \"memory\"` to keep sessions in the memory of one server process."),
89
94
  AUTH_C0024: withFix("Remove `secondaryStorage` from the static options. Return a Better Auth `secondaryStorage` adapter, an object with `get`, `set`, and `delete`, from the Definition callback."),
90
95
  AUTH_C0026: withFix("Set the option to a non-empty string, for example `provider: 'github'` or `method: 'GET'`."),
@@ -117,7 +122,7 @@ const authErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
117
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."),
118
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."),
119
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 } } }`."),
120
- 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` 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, 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`."),
121
126
  AUTH_C0057: withFix("Unset `VITEHUB_ADMIN_EMAILS`. List each admin's social account in `VITEHUB_ADMINS`, for example `VITEHUB_ADMINS=github:22072217`."),
122
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`."),
123
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."),
@@ -135,6 +140,7 @@ const authErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
135
140
  AUTH_C0068: withFix("Write each access route as a literal path, without percent-encoded pattern syntax or `.` and `..` segments. To guard a path and every path below it, end the route with `/**`, for example `/api/users/**` in place of `/api/users/:id` or `/api/admin/*`. Check the parameter in the handler."),
136
141
  AUTH_B0001: withFix("Set `env.projectRoot` of `@vite-hub/auth/nuxt` to the `projectRoot` of the `hubEnv()` plugin, or remove `env.projectRoot`."),
137
142
  AUTH_B0002: withFix("Remove `swr`, `cache`, `isr`, `prerender`, or `static` from the route rule that the message names. Or add a rule for the guarded path that turns the cache off, for example `routeRules: { '/dashboard/**': { cache: false, prerender: false } }`. If the page is public, remove the route from `access.routes`."),
143
+ AUTH_GUARDED_PAGE_CACHED: withFix("Remove `swr`, `cache`, `isr`, `prerender`, or `static` from the route rule that the message names. Or add a route rule that turns the cache off on the guarded pages and their payloads, for example `routeRules: { '/dashboard/**': { cache: false, prerender: false } }`. To keep the cache, add `ssr: false` to that route rule, so the page guard runs only in the browser. If the page is public, remove its page guard. To cache one public path beside a guarded page, add a public page with that static path, for example `pages/users/public.vue` with `definePageMeta({ auth: false })`, and use that exact path as the route rule key, for example `'/users/public': { swr: 60 }`."),
138
144
  AUTH_R0005: withFix("Add `server/auth.ts` with `export default defineAuth({})`. For a Nuxt layer, add it to the app."),
139
145
  AUTH_R0006: withFix("Send the `Origin` header with the request. Browsers send it. A server-side caller must set it, for example `headers: { origin: 'https://app.example.com' }`."),
140
146
  AUTH_R0007: withFix("Add the origin to Better Auth's `trustedOrigins` in the Auth Definition, for example `trustedOrigins: ['https://app.example.com']`. Or send the request from the app origin."),
@@ -170,5 +176,4 @@ const authErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
170
176
  }
171
177
  }
172
178
  });
173
- //#endregion
174
179
  export { authErrorDiagnostics as t };
@@ -1,9 +1,9 @@
1
- import { t as authErrorDiagnostics } from "./error-diagnostics-Dymr-S_n.js";
2
- import { t as isRecord } from "./object-Da1zyPCR.js";
1
+ import { t as authErrorDiagnostics } from "./error-diagnostics-BssJr_2t.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,8 +108,7 @@ 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",
@@ -302,5 +301,4 @@ function createDatabaseAuthEventStore(options) {
302
301
  }
303
302
  };
304
303
  }
305
- //#endregion
306
304
  export { checkGitHubOrgMember as a, parseAuthEventWindow as i, defaultAuthEventRetention as n, parseAuthEventList as r, createDatabaseAuthEventStore as t };
package/dist/forward.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { BetterAuthPlugin } from "better-auth";
2
- //#region src/forward.d.ts
3
2
  /**
4
3
  * Sign-in through a trusted reverse proxy, such as oauth2-proxy, Cloudflare Access, or Tailscale Serve. The proxy
5
4
  * sends the person's identity, or a credential for it, in a request header. Auth trusts the header only when `verify`
@@ -46,5 +45,4 @@ export declare const forwardAuthPluginId = "vitehub-forward-auth";
46
45
  * made for the identity before, or a new one, which also sets the session cookie on the response. When `verify` returns
47
46
  * `null`, the request keeps its own session cookie, if any.
48
47
  */
49
- export declare function forwardAuth(options: ForwardAuthOptions): BetterAuthPlugin;
50
- //#endregion
48
+ export declare function forwardAuth(options: ForwardAuthOptions): BetterAuthPlugin;
package/dist/forward.js CHANGED
@@ -1,8 +1,8 @@
1
- import { t as authErrorDiagnostics } from "./error-diagnostics-Dymr-S_n.js";
1
+ import { t as authErrorDiagnostics } from "./error-diagnostics-BssJr_2t.js";
2
2
  import { createAuthMiddleware } from "better-auth/api";
3
3
  import { applySetCookies, deleteSessionCookie, setSessionCookie } from "better-auth/cookies";
4
4
  import { handleOAuthUserInfo, setTokenUtil } from "better-auth/oauth2";
5
- //#region src/forward.ts
5
+ // src/forward.ts
6
6
  const forwardAuthPluginId = "vitehub-forward-auth";
7
7
  const nonEmpty = (value) => typeof value === "string" && value.trim().length > 0;
8
8
  function assertIdentity(value) {
@@ -116,5 +116,4 @@ function forwardAuth(options) {
116
116
  }] }
117
117
  };
118
118
  }
119
- //#endregion
120
119
  export { forwardAuth, forwardAuthPluginId };
package/dist/index.d.ts CHANGED
@@ -1,12 +1,10 @@
1
1
  /// <reference path="./host-declarations.d.ts" />
2
- import { A as AuthRuntimeOnlyOptions, At as AuthEventMetadata, B as RegisteredAuth, C as AuthOptions, D as AuthResolvedDefinitionOptions, Dt as AuthEventAggregates, E as AuthReservedOption, Et as AuthEventActor, F as AuthSessionRefreshContext, Ft as AuthEventWindow, H as ResolvedAuthViteConfig, I as AuthSessionRefreshFields, It as AuthEventsConfiguration, L as AuthSignInConfiguration, Lt as createDatabaseAuthEventStore, M as AuthRuntimeOptions, Mt as AuthEventRetention, N as AuthSessionOptions, Nt as AuthEventStore, O as AuthRuntimeContext, Ot as AuthEventCounts, P as AuthSessionRefresh, Pt as AuthEventType, R as AuthViteHubOptions, Rt as defaultAuthEventRetention, S as AuthGuardedHandler, Tt as AuthEvent, U as ViteHubAuth, Y as AuthConsoleColumn, _ as AuthDefinitionInput, a as AuthAccessPolicy, b as AuthDeleteAccountOptions, c as AuthAccessRouteConfiguration, d as AuthAnonymousGuardedHandler, g as AuthDefinition, gt as AuthConsoleRoles, h as AuthBetterAuthRuntimeOptions, i as AuthAccessConfiguration, j as AuthRuntimeOption, jt as AuthEventPage, k as AuthRuntimeEnv, kt as AuthEventListInput, l as AuthAnonymousAuthorization, lt as AuthConsoleOptions, m as AuthBetterAuthOptions, mt as AuthConsolePolicy, n as AuthAccessAuthorize, o as AuthAccessPolicyContext, p as AuthAuthorization, r as AuthAccessAuthorizeResult, s as AuthAccessRoute, t as AuthAccessAuthorizationContext, tt as AuthConsoleFieldPolicy, u as AuthAnonymousAuthorize, v as AuthDefinitionOptions, w as AuthRequest, wt as AuthDevice, x as AuthFor, y as AuthDefinitionResolver, z as DiscoveredAuthDefinition } from "./types-CruflEFI.js";
3
- import { n as AuthStatelessPreset, r as AuthStatelessPresetOptions, t as AuthPreset } from "./presets-CHndEv5i.js";
2
+ import { A as AuthRuntimeEnv, At as AuthEventActor, B as DiscoveredAuthDefinition, Bt as AuthEventsConfiguration, C as AuthGuardedHandler, D as AuthReservedOption, F as AuthSessionRefresh, Ft as AuthEventPage, Ht as defaultAuthEventRetention, I as AuthSessionRefreshContext, It as AuthEventRetention, L as AuthSessionRefreshFields, Lt as AuthEventStore, M as AuthRuntimeOption, Mt as AuthEventCounts, N as AuthRuntimeOptions, Nt as AuthEventListInput, O as AuthResolvedDefinitionOptions, Ot as AuthDevice, P as AuthSessionOptions, Pt as AuthEventMetadata, R as AuthSignInConfiguration, Rt as AuthEventType, S as AuthFor, T as AuthRequest, U as ResolvedAuthViteConfig, V as RegisteredAuth, Vt as createDatabaseAuthEventStore, W as ViteHubAuth, X as AuthConsoleColumn, _ as AuthDefinition, _t as AuthConsoleRoles, a as AuthAccessPolicy, b as AuthDefinitionResolver, c as AuthAccessRouteConfiguration, d as AuthAnonymousGuardedHandler, g as AuthComponentsOptions, h as AuthBetterAuthRuntimeOptions, ht as AuthConsolePolicy, i as AuthAccessConfiguration, j as AuthRuntimeOnlyOptions, jt as AuthEventAggregates, k as AuthRuntimeContext, kt as AuthEvent, l as AuthAnonymousAuthorization, m as AuthBetterAuthOptions, n as AuthAccessAuthorize, nt as AuthConsoleFieldPolicy, o as AuthAccessPolicyContext, p as AuthAuthorization, r as AuthAccessAuthorizeResult, s as AuthAccessRoute, t as AuthAccessAuthorizationContext, u as AuthAnonymousAuthorize, ut as AuthConsoleOptions, v as AuthDefinitionInput, w as AuthOptions, x as AuthDeleteAccountOptions, y as AuthDefinitionOptions, z as AuthViteHubOptions, zt as AuthEventWindow } from "./types-BHSgxyvV.js";
3
+ import { n as checksOwnAccess } from "./own-access-C22hSIuF.js";
4
+ import { n as AuthStatelessPreset, r as AuthStatelessPresetOptions, t as AuthPreset } from "./presets-C6AtiRdI.js";
4
5
  import { Result } from "@vite-hub/runtime";
5
- //#region src/definition.d.ts
6
6
  export declare function defineAuth<const TOptions extends AuthResolvedDefinitionOptions>(options: AuthDefinitionResolver<TOptions>): AuthDefinition<AuthDefinitionResolver<TOptions>>;
7
7
  export declare function defineAuth<const TOptions extends AuthBetterAuthOptions & Pick<AuthViteHubOptions, "database" | "runtime">>(options: AuthDefinitionOptions<TOptions>): AuthDefinition<AuthDefinitionOptions<TOptions>>;
8
- //#endregion
9
- //#region src/github.d.ts
10
8
  interface GitHubOrgMemberOptions {
11
9
  /** Reuse a successful check no older than this many milliseconds per token and organization. Default: no cache. */
12
10
  cacheMs?: number;
@@ -20,5 +18,4 @@ type GitHubOrgMemberErrorCode = "AUTH_GITHUB_NOT_ORG_MEMBER" | "AUTH_GITHUB_ORG_
20
18
  * Returns `[undefined, undefined]` for an active membership, else the error that says why it could not confirm one.
21
19
  */
22
20
  export declare function checkGitHubOrgMember(accessToken: string | null | undefined, org: string, options?: GitHubOrgMemberOptions): Promise<Result<void, GitHubOrgMemberErrorCode>>;
23
- //#endregion
24
- export { type AuthAccessAuthorizationContext, type AuthAccessAuthorize, type AuthAccessAuthorizeResult, type AuthAccessConfiguration, type AuthAccessPolicy, type AuthAccessPolicyContext, type AuthAccessRoute, type AuthAccessRouteConfiguration, type AuthAnonymousAuthorization, type AuthAnonymousAuthorize, type AuthAnonymousGuardedHandler, type AuthAuthorization, type AuthBetterAuthOptions, type AuthBetterAuthRuntimeOptions, type AuthConsoleColumn, type AuthConsoleFieldPolicy, type AuthConsoleOptions, type AuthConsolePolicy, type AuthConsoleRoles, type AuthDefinition, type AuthDefinitionInput, type AuthDefinitionOptions, type AuthDefinitionResolver, type AuthDeleteAccountOptions, type AuthDevice, type AuthEvent, type AuthEventActor, type AuthEventAggregates, type AuthEventCounts, type AuthEventListInput, type AuthEventMetadata, type AuthEventPage, type AuthEventRetention, type AuthEventStore, type AuthEventType, type AuthEventWindow, type AuthEventsConfiguration, type AuthFor, type AuthGuardedHandler, type AuthOptions, type AuthPreset, type AuthRequest, type AuthReservedOption, type AuthResolvedDefinitionOptions, type AuthRuntimeContext, type AuthRuntimeEnv, type AuthRuntimeOnlyOptions, type AuthRuntimeOption, type AuthRuntimeOptions, type AuthSessionOptions, type AuthSessionRefresh, type AuthSessionRefreshContext, type AuthSessionRefreshFields, type AuthSignInConfiguration, type AuthStatelessPreset, type AuthStatelessPresetOptions, type AuthViteHubOptions, type DiscoveredAuthDefinition, type GitHubOrgMemberErrorCode, type GitHubOrgMemberOptions, type RegisteredAuth, type ResolvedAuthViteConfig, type ViteHubAuth, createDatabaseAuthEventStore, defaultAuthEventRetention };
21
+ export { type AuthAccessAuthorizationContext, type AuthAccessAuthorize, type AuthAccessAuthorizeResult, type AuthAccessConfiguration, type AuthAccessPolicy, type AuthAccessPolicyContext, type AuthAccessRoute, type AuthAccessRouteConfiguration, type AuthAnonymousAuthorization, type AuthAnonymousAuthorize, type AuthAnonymousGuardedHandler, type AuthAuthorization, type AuthBetterAuthOptions, type AuthBetterAuthRuntimeOptions, type AuthComponentsOptions, type AuthConsoleColumn, type AuthConsoleFieldPolicy, type AuthConsoleOptions, type AuthConsolePolicy, type AuthConsoleRoles, type AuthDefinition, type AuthDefinitionInput, type AuthDefinitionOptions, type AuthDefinitionResolver, type AuthDeleteAccountOptions, type AuthDevice, type AuthEvent, type AuthEventActor, type AuthEventAggregates, type AuthEventCounts, type AuthEventListInput, type AuthEventMetadata, type AuthEventPage, type AuthEventRetention, type AuthEventStore, type AuthEventType, type AuthEventWindow, type AuthEventsConfiguration, type AuthFor, type AuthGuardedHandler, type AuthOptions, type AuthPreset, type AuthRequest, type AuthReservedOption, type AuthResolvedDefinitionOptions, type AuthRuntimeContext, type AuthRuntimeEnv, type AuthRuntimeOnlyOptions, type AuthRuntimeOption, type AuthRuntimeOptions, type AuthSessionOptions, type AuthSessionRefresh, type AuthSessionRefreshContext, type AuthSessionRefreshFields, type AuthSignInConfiguration, type AuthStatelessPreset, type AuthStatelessPresetOptions, type AuthViteHubOptions, type DiscoveredAuthDefinition, type GitHubOrgMemberErrorCode, type GitHubOrgMemberOptions, type RegisteredAuth, type ResolvedAuthViteConfig, type ViteHubAuth, checksOwnAccess, createDatabaseAuthEventStore, defaultAuthEventRetention };
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
- import { a as checkGitHubOrgMember, n as defaultAuthEventRetention, t as createDatabaseAuthEventStore } from "./events-DCfuicoo.js";
2
- import { n as defineAuth } from "./definition-BCaLA9kW.js";
3
- export { checkGitHubOrgMember, createDatabaseAuthEventStore, defaultAuthEventRetention, defineAuth };
1
+ import { n as defineAuth } from "./definition-MDGMNKrK.js";
2
+ import { a as checkGitHubOrgMember, n as defaultAuthEventRetention, t as createDatabaseAuthEventStore } from "./events-DZqMiae_.js";
3
+ import { n as checksOwnAccess } from "./own-access-DQgqxTbI.js";
4
+ export { checkGitHubOrgMember, checksOwnAccess, createDatabaseAuthEventStore, defaultAuthEventRetention, defineAuth };
@@ -1,5 +1,5 @@
1
1
  /// <reference path="../host-declarations.d.ts" />
2
- import { C as requireCaller, D as withAnonymousAuthorization, E as useAuth, M as getAuthForDefinition, O as withAuth, S as requireAuthorization, T as toAuthRequest, _ as handleAuthRequest, a as authRoute, b as requireAuth, c as createAuth, d as createAuthHandler, f as createAuthRequestRuntimeOptions, g as handleAuth, h as getAuthEvents, i as assertAuthOrigin, j as createBetterAuthOptions, k as withAuthorization, l as createAuthAccessHandler, m as getAuthConsoleForRequest, n as AuthSignOutOptions, o as can, p as getAuth, r as aggregateAuthEvents, s as checkAuthMember, t as AuthEventReadErrorCode, u as createAuthForRequest, v as listAuthEvents, w as signOut, x as requireAuthAccessRoutes, y as requireAbility } from "../server-BM-RSf1T.js";
3
- import { a as setAuthAccessIdentityResolver, o as setAuthRuntimeEnvResolver, s as resetAuth } from "../server-C8TlOrSy.js";
4
- import { n as AbilityErrorData, t as AbilityError } from "../ability-error-DcgChwCN.js";
5
- export { AbilityError, type AbilityErrorData, AuthEventReadErrorCode, AuthSignOutOptions, aggregateAuthEvents, assertAuthOrigin, can, checkAuthMember, createAuth, createAuthAccessHandler, createAuthForRequest, createAuthHandler, createAuthRequestRuntimeOptions, createBetterAuthOptions, authRoute as default, getAuth, getAuthConsoleForRequest, getAuthEvents, getAuthForDefinition, handleAuth, handleAuthRequest, listAuthEvents, requireAbility, requireAuth, requireAuthAccessRoutes, requireAuthorization, requireCaller, resetAuth, setAuthAccessIdentityResolver, setAuthRuntimeEnvResolver, signOut, toAuthRequest, useAuth, withAnonymousAuthorization, withAuth, withAuthorization };
2
+ import { C as requireCaller, D as withAnonymousAuthorization, E as useAuth, M as findVerifiedAuthUserId, N as getAuthForDefinition, O as withAuth, S as requireAuthorization, T as toAuthRequest, _ as handleAuthRequest, a as authRoute, b as requireAuth, c as createAuth, d as createAuthHandler, f as createAuthRequestRuntimeOptions, g as handleAuth, h as getAuthEvents, i as assertAuthOrigin, j as createBetterAuthOptions, k as withAuthorization, l as createAuthAccessHandler, m as getAuthConsoleForRequest, n as AuthSignOutOptions, o as can, p as getAuth, r as aggregateAuthEvents, s as checkAuthMember, t as AuthEventReadErrorCode, u as createAuthForRequest, v as listAuthEvents, w as signOut, x as requireAuthAccessRoutes, y as requireAbility } from "../server-CFWlYQJb.js";
3
+ import { a as setAuthAccessIdentityResolver, o as setAuthRuntimeEnvResolver, s as resetAuth } from "../server-DCsgxFPP.js";
4
+ import { n as AbilityErrorData, t as AbilityError } from "../ability-error-C1c30O6E.js";
5
+ export { AbilityError, type AbilityErrorData, AuthEventReadErrorCode, AuthSignOutOptions, aggregateAuthEvents, assertAuthOrigin, can, checkAuthMember, createAuth, createAuthAccessHandler, createAuthForRequest, createAuthHandler, createAuthRequestRuntimeOptions, createBetterAuthOptions, authRoute as default, findVerifiedAuthUserId, getAuth, getAuthConsoleForRequest, getAuthEvents, getAuthForDefinition, handleAuth, handleAuthRequest, listAuthEvents, requireAbility, requireAuth, requireAuthAccessRoutes, requireAuthorization, requireCaller, resetAuth, setAuthAccessIdentityResolver, setAuthRuntimeEnvResolver, signOut, toAuthRequest, useAuth, withAnonymousAuthorization, withAuth, withAuthorization };