@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,18 +1,19 @@
1
- import { t as authErrorDiagnostics } from "./error-diagnostics-Dymr-S_n.js";
2
- import { n as isRecordOrFunction, t as isRecord$1 } from "./object-Da1zyPCR.js";
3
- import { i as resetAuth } from "./runtime-state-ojQCzKOc.js";
4
- import { t as invariant } from "./invariant-D8_xBqmZ.js";
5
- import { r as resolveAccessRoutePath, t as accessRouteSyntaxError } from "./application-path-DuTpfGFj.js";
6
- import { t as normalizeAuthBasePath } from "./shared-DRtfuFsV.js";
7
- import { a as authDatabaseSchemaError, i as authDatabasePlacementError, n as authDatabaseAdditionalFieldsError, o as authMemoryDatabaseError, t as assertAuthDatabaseIdStrategy } from "./database-options-DpOVjUti.js";
8
- import { i as resolveAuthTableSpecs, n as authSqlName } from "./table-specs-CURphR3n.js";
1
+ import { t as invariant } from "./invariant-Dj2R1eMr.js";
2
+ import { t as createNitroServerKit } from "./nitro-kit-Bg4xUZAI.js";
3
+ import { t as isRecord$1 } from "./object-CAK6UYR5.js";
4
+ import { r as resolveAccessRoutePath, t as accessRouteSyntaxError } from "./application-path-zKi7NrvK.js";
5
+ import { t as authErrorDiagnostics } from "./error-diagnostics-BssJr_2t.js";
6
+ import { a as normalizeAuthBasePath, n as assertAuthPages } from "./access-pages-BwImVHN_.js";
7
+ import { a as authDatabaseSchemaError, i as authDatabasePlacementError, n as authDatabaseAdditionalFieldsError, o as authMemoryDatabaseError, t as assertAuthDatabaseIdStrategy } from "./database-options-DQ-8qYMl.js";
8
+ import { i as resolveAuthTableSpecs, n as authSqlName } from "./table-specs-jw0jjU6l.js";
9
+ import { i as resetAuth } from "./runtime-state-DtKUfxKq.js";
9
10
  import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
10
11
  import { basename, dirname, join, parse, relative, resolve } from "node:path";
11
12
  import { fileURLToPath } from "node:url";
12
13
  import { tmpdir } from "node:os";
13
14
  import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
14
15
  import { parseSync } from "vite";
15
- //#region ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs
16
+ // ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs
16
17
  const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
17
18
  function normalizeWindowsPath(input = "") {
18
19
  if (!input) return input;
@@ -33,10 +34,10 @@ const resolve$1 = function(...arguments_) {
33
34
  const path = index >= 0 ? arguments_[index] : cwd();
34
35
  if (!path || path.length === 0) continue;
35
36
  resolvedPath = `${path}/${resolvedPath}`;
36
- resolvedAbsolute = isAbsolute(path);
37
+ resolvedAbsolute = isAbsolute$1(path);
37
38
  }
38
39
  resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
39
- if (resolvedAbsolute && !isAbsolute(resolvedPath)) return `/${resolvedPath}`;
40
+ if (resolvedAbsolute && !isAbsolute$1(resolvedPath)) return `/${resolvedPath}`;
40
41
  return resolvedPath.length > 0 ? resolvedPath : ".";
41
42
  };
42
43
  function normalizeString(path, allowAboveRoot) {
@@ -89,7 +90,7 @@ function normalizeString(path, allowAboveRoot) {
89
90
  }
90
91
  return res;
91
92
  }
92
- const isAbsolute = function(p) {
93
+ const isAbsolute$1 = function(p) {
93
94
  return _IS_ABSOLUTE_RE.test(p);
94
95
  };
95
96
  const relative$1 = function(from, to) {
@@ -107,10 +108,9 @@ const relative$1 = function(from, to) {
107
108
  const dirname$1 = function(p) {
108
109
  const segments = normalizeWindowsPath(p).replace(/\/$/, "").split("/").slice(0, -1);
109
110
  if (segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0])) segments[0] += "/";
110
- return segments.join("/") || (isAbsolute(p) ? "/" : ".");
111
+ return segments.join("/") || (isAbsolute$1(p) ? "/" : ".");
111
112
  };
112
- //#endregion
113
- //#region ../internal/src/inspect.ts
113
+ // ../internal/src/inspect.ts
114
114
  function relativeDefinitionFile(projectRoot, file) {
115
115
  return relative$1(projectRoot, file).replaceAll("\\", "/");
116
116
  }
@@ -126,8 +126,7 @@ function summarizeDefinitions(projectRoot, definitions, fallbackSource) {
126
126
  const secretKeyPattern = /secret|token|passw(?:or)?d|credential|api[-_\s]?key|private[-_\s]?key|authorization|cookie|signature|dsn|connection[-_\s]?string/i;
127
127
  new RegExp(String.raw`\b([\w-]*authorization[\w-]*["']?\s*[:=]\s*)(?!\[redacted\](?=$|[\s,;}&]))(?:"(?:\\[^\r\n]|[^"\\\r\n])*"|'(?:\\[^\r\n]|[^'\\\r\n])*'|[^\r\n]+?(?=\s*(?:[,;])?\s*(?:${secretKeyPattern.source})[\w-]*\s*[:=]|\s+rejected\b|$))`, "gi");
128
128
  new RegExp(String.raw`\b([\w-]*(?:${secretKeyPattern.source})[\w-]*["']?\s*[:=]\s*)(?!\[redacted\](?=$|[\s,;}&]))(?:"(?:\\[^\r\n]|[^"\\\r\n])*"|'(?:\\[^\r\n]|[^'\\\r\n])*'|[^\s,;&#&]+)`, "gi");
129
- //#endregion
130
- //#region ../internal/src/build/vite.ts
129
+ // ../internal/src/build/vite.ts
131
130
  const generatedViteHubFilesPattern = "**/.vitehub/**";
132
131
  const projectRootDirectoryMarkers = [
133
132
  ["server", "agents"],
@@ -214,7 +213,7 @@ function hasProjectRootDirectoryMarker(root) {
214
213
  for (const marker of projectRootDirectoryMarkers) try {
215
214
  if (statSync(resolve(root, ...marker)).isDirectory()) return true;
216
215
  } catch (error) {
217
- if (error.code !== "ENOENT") throw error;
216
+ if (!isMissingProjectMarker(error)) throw error;
218
217
  }
219
218
  return false;
220
219
  }
@@ -228,13 +227,82 @@ function hasProjectRootFileMarker(root, markers) {
228
227
  try {
229
228
  if (statSync(resolve(root, ...path)).isFile()) return true;
230
229
  } catch (error) {
231
- if (error.code !== "ENOENT") throw error;
230
+ if (!isMissingProjectMarker(error)) throw error;
232
231
  }
233
232
  }
234
233
  return false;
235
234
  }
236
- //#endregion
237
- //#region ../internal/src/build/paths.ts
235
+ function isMissingProjectMarker(error) {
236
+ const code = error.code;
237
+ return code === "ENOENT" || code === "ENOTDIR";
238
+ }
239
+ // src/route-rule-cache.ts
240
+ /** Route rules that keep one response and serve it to many visitors. */
241
+ const cachingRuleNames = [
242
+ "cache",
243
+ "isr",
244
+ "prerender",
245
+ "static"
246
+ ];
247
+ /** Nitro caches and prerenders only GET and HEAD requests. */
248
+ const cachedMethods = ["GET", "HEAD"];
249
+ /** On one pattern, h3 merges the rules for every method first, then GET rules, then HEAD rules. */
250
+ const methodOrder = [
251
+ "",
252
+ "GET",
253
+ "HEAD"
254
+ ];
255
+ /** h3 applies the GET rules of a pattern to HEAD requests too. */
256
+ function appliesTo(entry, method) {
257
+ return !entry.method || entry.method === method || method === "HEAD" && entry.method === "GET";
258
+ }
259
+ /**
260
+ * Reads the route rules that Nitro serves and returns a function that finds a route rule that caches or prerenders a
261
+ * guarded rou3 pattern. `toPattern` maps the path of a rule key to the rou3 pattern that the guard pattern is compared
262
+ * with.
263
+ *
264
+ * The finder compares patterns, not sample paths. A rule that caches and matches at least one guarded path counts,
265
+ * unless a `false` value of the same rule turns the cache off on all of these paths: the `false` rule must match every
266
+ * guarded path, or every path of the caching rule, and h3 must merge it after the caching rule. A cache that more than
267
+ * one `false` rule turns off together still counts. `toPattern` can fold the case of the rule paths, as Nuxt does when
268
+ * its router is not case sensitive.
269
+ */
270
+ async function createCachingRouteRuleFinder(routeRules, toPattern = (path) => path) {
271
+ const [{ normalizeRouteRules }, { compareRoutes, routesOverlap }] = await Promise.all([import("h3/rules"), import("rou3")]);
272
+ const entries = Object.entries(normalizeRouteRules(routeRules)).map(([key, rules]) => {
273
+ const [, method = "", path = key] = /^([A-Z]+) (\/.*)$/.exec(key) ?? [];
274
+ return {
275
+ key,
276
+ method,
277
+ pattern: toPattern(path),
278
+ rules
279
+ };
280
+ });
281
+ return (guarded, { methods = cachedMethods, names = cachingRuleNames, exempt } = {}) => {
282
+ for (const method of methods) {
283
+ const applied = entries.filter((entry) => appliesTo(entry, method));
284
+ for (const name of names) {
285
+ const turnsOff = (entry, off) => {
286
+ if (off.rules[name] !== false) return false;
287
+ const relation = compareRoutes(off.pattern, entry.pattern);
288
+ if (relation === "equal") return methodOrder.indexOf(off.method) > methodOrder.indexOf(entry.method);
289
+ return relation === "subset" && ["equal", "superset"].includes(compareRoutes(off.pattern, guarded));
290
+ };
291
+ for (const entry of applied) {
292
+ const value = entry.rules[name];
293
+ if (value === void 0 || value === false || !routesOverlap(guarded, entry.pattern)) continue;
294
+ if (applied.some((off) => turnsOff(entry, off)) || exempt?.(entry, applied, name)) continue;
295
+ return {
296
+ key: entry.key,
297
+ name,
298
+ method
299
+ };
300
+ }
301
+ }
302
+ }
303
+ };
304
+ }
305
+ // ../internal/src/build/paths.ts
238
306
  function resolveRuntimeModule(packageDir, modulePath) {
239
307
  const distFile = resolve$1(packageDir, "dist", `${modulePath}.js`);
240
308
  return existsSync(distFile) ? distFile : resolve$1(packageDir, "src", `${modulePath}.ts`);
@@ -261,45 +329,14 @@ function findPackageDir(file) {
261
329
  function ownModule(importMetaUrl, modulePath) {
262
330
  return resolveRuntimeModule(findPackageDir(fileURLToPath(importMetaUrl)), modulePath);
263
331
  }
264
- //#endregion
265
- //#region ../internal/src/nitro-kit.ts
266
- function cloneArray(value) {
267
- return Array.isArray(value) ? [...value] : [];
268
- }
269
- function sameHandler(left, right) {
270
- return left.handler === right.handler && left.route === right.route && left.method === right.method && left.middleware === right.middleware;
271
- }
272
- /** Create a Nitro 3 configuration builder for generated ViteHub output. */
273
- function createNitroServerKit(value = {}) {
274
- const config = isRecordOrFunction(value) ? { ...value } : {};
275
- const handlers = cloneArray(config.handlers);
276
- const plugins = cloneArray(config.plugins);
277
- config.handlers = handlers;
278
- config.plugins = plugins;
279
- return {
280
- config,
281
- addHandler(handler, position = "end") {
282
- if (handlers.some((candidate) => isRecordOrFunction(candidate) && sameHandler(candidate, handler))) return;
283
- if (position === "start") handlers.unshift({ ...handler });
284
- else handlers.push({ ...handler });
285
- },
286
- addPlugin(plugin, position = "end") {
287
- if (plugins.includes(plugin)) return;
288
- if (position === "start") plugins.unshift(plugin);
289
- else plugins.push(plugin);
290
- }
291
- };
292
- }
293
- //#endregion
294
- //#region ../internal/src/definition-catalog.ts
332
+ // ../internal/src/definition-catalog.ts
295
333
  /** `writeFileIfChangedSync` for async callers. */
296
334
  async function writeFileIfChanged(file, contents) {
297
335
  if (await readFile(file, "utf8").catch(() => void 0) === contents) return;
298
336
  await mkdir(resolve$1(file, ".."), { recursive: true });
299
337
  await writeFile(file, contents, "utf8");
300
338
  }
301
- //#endregion
302
- //#region ../internal/src/contributions.ts
339
+ // ../internal/src/contributions.ts
303
340
  function isThenable(value) {
304
341
  return typeof value.then === "function";
305
342
  }
@@ -326,27 +363,7 @@ async function flattenPluginOptions(plugins) {
326
363
  await flattenPlugins(plugins ?? [], flattened, /* @__PURE__ */ new Set());
327
364
  return flattened;
328
365
  }
329
- //#endregion
330
- //#region src/access-route-cache.ts
331
- /** Route rules that keep one response and serve it to many visitors. Nitro stores `swr` as `cache`. */
332
- const cachingRuleNames = [
333
- "cache",
334
- "isr",
335
- "prerender",
336
- "static"
337
- ];
338
- /** Nitro caches and prerenders only GET and HEAD requests. */
339
- const cachedMethods = ["GET", "HEAD"];
340
- /** On one pattern, h3 merges the rules for every method first, then GET rules, then HEAD rules. */
341
- const methodOrder = [
342
- "",
343
- "GET",
344
- "HEAD"
345
- ];
346
- /** h3 applies the GET rules of a pattern to HEAD requests too. */
347
- function appliesTo(entry, method) {
348
- return !entry.method || entry.method === method || method === "HEAD" && entry.method === "GET";
349
- }
366
+ // src/access-route-cache.ts
350
367
  /**
351
368
  * The rou3 pattern of the paths that the access middleware guards for a route. The middleware matches the path
352
369
  * literally, so the pattern escapes every character that rou3 reads as syntax. In rou3, `/**` also matches the path
@@ -359,55 +376,27 @@ function accessRoutePattern(route, baseURL) {
359
376
  }
360
377
  /**
361
378
  * Stops the build when a route rule caches or prerenders a path that `access.routes` guards. The cache would keep the
362
- * response of one visitor and serve it to others.
363
- *
364
- * The check compares patterns, not sample paths. A rule that caches and matches at least one guarded path fails,
365
- * unless a `false` value of the same rule turns the cache off on all of these paths: the `false` rule must match every
366
- * guarded path, or every path of the caching rule, and h3 must merge it after the caching rule. A cache that more than
367
- * one `false` rule turns off together still fails. A rule whose paths are all in one route of `publicRoutes` passes,
368
- * because the middleware guards none of them.
379
+ * response of one visitor and serve it to others. `createCachingRouteRuleFinder` holds the rules of the check. A rule
380
+ * whose paths are all in one route of `publicRoutes` passes, because the middleware guards none of them.
369
381
  */
370
382
  async function assertNoCachedAccessRoutes(routes, routeRules, baseURL = "/", publicRoutes = []) {
371
383
  const guards = routes.filter((route) => !route.method || cachedMethods.includes(route.method.toUpperCase()));
372
384
  if (!guards.length || !Object.keys(routeRules).length) return;
373
- const [{ normalizeRouteRules }, { compareRoutes, routesOverlap }] = await Promise.all([import("h3/rules"), import("rou3")]);
374
385
  const base = baseURL.replace(/\/$/, "");
375
- const entries = Object.entries(normalizeRouteRules(routeRules)).map(([key, rules]) => {
376
- const [, method = "", path = key] = /^([A-Z]+) (\/.*)$/.exec(key) ?? [];
377
- return {
378
- key,
379
- method,
380
- pattern: `${base}${path}`,
381
- rules
382
- };
383
- });
386
+ const [findCachingRule, { compareRoutes }] = await Promise.all([createCachingRouteRuleFinder(routeRules, (path) => `${base}${path}`), import("rou3")]);
384
387
  const exceptions = publicRoutes.map((route) => accessRoutePattern(route, baseURL));
385
388
  const isPublic = (entry) => exceptions.some((pattern) => ["equal", "superset"].includes(compareRoutes(pattern, entry.pattern)));
386
389
  for (const guard of guards) {
387
- const guarded = accessRoutePattern(guard.route, baseURL);
388
390
  const method = guard.method?.toUpperCase();
389
- const methods = !method || method === "GET" ? cachedMethods : [method];
390
- for (const method of methods) {
391
- const applied = entries.filter((entry) => appliesTo(entry, method));
392
- for (const name of cachingRuleNames) {
393
- const turnsOff = (entry, off) => {
394
- if (off.rules[name] !== false) return false;
395
- const relation = compareRoutes(off.pattern, entry.pattern);
396
- if (relation === "equal") return methodOrder.indexOf(off.method) > methodOrder.indexOf(entry.method);
397
- return relation === "subset" && ["equal", "superset"].includes(compareRoutes(off.pattern, guarded));
398
- };
399
- for (const entry of applied) {
400
- const value = entry.rules[name];
401
- if (value === void 0 || value === false || !routesOverlap(guarded, entry.pattern) || isPublic(entry)) continue;
402
- if (applied.some((off) => turnsOff(entry, off))) continue;
403
- throw authErrorDiagnostics.AUTH_B0002({ message: `[vitehub] Route rule ${JSON.stringify(entry.key)} sets \`${name}\` on ${method} requests to paths that the \`access.routes\` entry ${JSON.stringify(guard.route)} guards. A cached or prerendered response is made for one visitor and served to others.` });
404
- }
405
- }
406
- }
391
+ const cached = findCachingRule(accessRoutePattern(guard.route, baseURL), {
392
+ exempt: isPublic,
393
+ ...method && method !== "GET" ? { methods: [method] } : {}
394
+ });
395
+ if (!cached) continue;
396
+ throw authErrorDiagnostics.AUTH_B0002({ message: `[vitehub] Route rule ${JSON.stringify(cached.key)} sets \`${cached.name}\` on ${cached.method} requests to paths that the \`access.routes\` entry ${JSON.stringify(guard.route)} guards. A cached or prerendered response is made for one visitor and served to others.` });
407
397
  }
408
398
  }
409
- //#endregion
410
- //#region ../internal/src/build/ast-walk.ts
399
+ // ../internal/src/build/ast-walk.ts
411
400
  /** The oxc parser grammar for a file, from its extension. Defaults to TypeScript. */
412
401
  function moduleLanguage(file) {
413
402
  if (/\.(?:c|m)?tsx$/i.test(file)) return "tsx";
@@ -430,8 +419,7 @@ function walk(node, visit, parent) {
430
419
  } else if (isNode(child)) walk(child, visit, node);
431
420
  }
432
421
  }
433
- //#endregion
434
- //#region ../internal/src/build/scan-module.ts
422
+ // ../internal/src/build/scan-module.ts
435
423
  /**
436
424
  * Reads facts from JavaScript and TypeScript modules at build and dev time. The scanner parses each module once with
437
425
  * the oxc parser that Vite ships through Rolldown, and never runs it. Values that are not static literals read as
@@ -562,8 +550,7 @@ function staticString(node) {
562
550
  const value = staticValue(node);
563
551
  return typeof value === "string" ? value : void 0;
564
552
  }
565
- //#endregion
566
- //#region src/discovery.ts
553
+ // src/discovery.ts
567
554
  const authDefinitionExtensions = [
568
555
  ".ts",
569
556
  ".mts",
@@ -636,8 +623,7 @@ function discoverAuthAbilities(rootDir, options = {}) {
636
623
  if (found.length > 1) throw authErrorDiagnostics.AUTH_C0060({ message: ["[vitehub] Only one abilities file is allowed. Found:", ...found.map((file) => ` - ${file}`)].join("\n") });
637
624
  return found[0];
638
625
  }
639
- //#endregion
640
- //#region src/config.ts
626
+ // src/config.ts
641
627
  const authDatabaseModules = /* @__PURE__ */ new Set(["@vite-hub/auth/database", "vite-hub/auth/database"]);
642
628
  function readAuthDatabaseImports(module) {
643
629
  const names = /* @__PURE__ */ new Set();
@@ -662,24 +648,181 @@ const authSchemaPluginImports = {
662
648
  "@better-auth/api-key": { apiKey: "apiKey" },
663
649
  "@better-auth/stripe": { stripe: "stripe" }
664
650
  };
665
- /** The plugins of `AuthSchemaPlugin` that `module` imports and calls, such as `twoFactor()` from `better-auth/plugins`. */
666
- function readAuthSchemaPlugins(module) {
667
- const locals = /* @__PURE__ */ new Map();
668
- for (const statement of module.program.body) {
669
- if (statement.type !== "ImportDeclaration" || statement.importKind === "type") continue;
670
- const source = statement.source.value.startsWith("better-auth/plugins/") ? "better-auth/plugins" : statement.source.value;
671
- const exports = authSchemaPluginImports[source];
672
- if (!exports) continue;
651
+ const viteExtensions = [
652
+ ".mjs",
653
+ ".js",
654
+ ".mts",
655
+ ".ts",
656
+ ".jsx",
657
+ ".tsx",
658
+ ".json"
659
+ ];
660
+ const typeScriptSources = {
661
+ ".js": [".ts", ".tsx"],
662
+ ".jsx": [".tsx"],
663
+ ".mjs": [".mts"],
664
+ ".cjs": [".cts"]
665
+ };
666
+ const isFile = (file) => existsSync(file) && statSync(file).isFile();
667
+ /**
668
+ * The file of a relative import, resolved in the order Vite uses: the file itself, the TypeScript source of a `.js`
669
+ * path, the path with each extension, then the `index` file of the folder.
670
+ */
671
+ function resolveLocalModule(importer, specifier) {
672
+ const path = resolve(dirname(importer), specifier);
673
+ if (isFile(path)) return path;
674
+ const extension = Object.keys(typeScriptSources).find((item) => path.endsWith(item));
675
+ return [
676
+ ...extension ? typeScriptSources[extension].map((item) => path.slice(0, -extension.length) + item) : [],
677
+ ...viteExtensions.map((item) => path + item),
678
+ ...viteExtensions.map((item) => resolve(path, `index${item}`))
679
+ ].find(isFile);
680
+ }
681
+ const nameOf = (node) => node.type === "Identifier" ? node.name : String(node.value);
682
+ function addBoundNames(pattern, names) {
683
+ walk(pattern, (node) => {
684
+ if (node.type === "Identifier") names.push(node.name);
685
+ if (node.type === "AssignmentPattern") {
686
+ addBoundNames(node.left, names);
687
+ return false;
688
+ }
689
+ });
690
+ }
691
+ function readModuleBindings(module) {
692
+ const bindings = {
693
+ declarations: /* @__PURE__ */ new Map(),
694
+ imports: /* @__PURE__ */ new Map(),
695
+ exports: /* @__PURE__ */ new Map(),
696
+ exportAll: [],
697
+ pluginFactories: /* @__PURE__ */ new Map()
698
+ };
699
+ const localFile = (specifier) => specifier.startsWith("./") || specifier.startsWith("../") ? resolveLocalModule(module.file, specifier) : void 0;
700
+ const declare = (name, node) => bindings.declarations.set(name, [...bindings.declarations.get(name) ?? [], node]);
701
+ const readDeclaration = (declaration, exported) => {
702
+ const names = [];
703
+ if ((declaration.type === "FunctionDeclaration" || declaration.type === "ClassDeclaration") && declaration.id) names.push(declaration.id.name);
704
+ if (declaration.type === "VariableDeclaration") for (const declarator of declaration.declarations) {
705
+ const bound = [];
706
+ addBoundNames(declarator.id, bound);
707
+ for (const name of bound) declare(name, declarator);
708
+ names.push(...bound);
709
+ }
710
+ else for (const name of names) declare(name, declaration);
711
+ if (exported) for (const name of names) bindings.exports.set(name, { local: name });
712
+ };
713
+ for (const statement of module.program.body) if (statement.type === "ImportDeclaration") {
714
+ if (statement.importKind === "type") continue;
715
+ const source = statement.source.value;
716
+ const factories = authSchemaPluginImports[source.startsWith("better-auth/plugins/") ? "better-auth/plugins" : source];
717
+ const file = localFile(source);
673
718
  for (const specifier of statement.specifiers) {
674
- if (specifier.type !== "ImportSpecifier" || specifier.importKind === "type") continue;
675
- const imported = specifier.imported.type === "Identifier" ? specifier.imported.name : specifier.imported.value;
676
- if (Object.hasOwn(exports, imported)) locals.set(specifier.local.name, exports[imported]);
719
+ if (specifier.type === "ImportSpecifier" && specifier.importKind === "type") continue;
720
+ const imported = specifier.type === "ImportSpecifier" ? nameOf(specifier.imported) : specifier.type === "ImportDefaultSpecifier" ? "default" : "*";
721
+ if (factories && Object.hasOwn(factories, imported)) bindings.pluginFactories.set(specifier.local.name, factories[imported]);
722
+ if (file) bindings.imports.set(specifier.local.name, {
723
+ file,
724
+ imported
725
+ });
677
726
  }
678
- }
727
+ } else if (statement.type === "ExportNamedDeclaration") {
728
+ if (statement.exportKind === "type") continue;
729
+ if (statement.declaration) readDeclaration(statement.declaration, true);
730
+ const file = statement.source ? localFile(statement.source.value) : void 0;
731
+ for (const specifier of statement.specifiers) {
732
+ if (specifier.exportKind === "type") continue;
733
+ const local = nameOf(specifier.local);
734
+ if (statement.source) {
735
+ if (file) bindings.exports.set(nameOf(specifier.exported), {
736
+ file,
737
+ imported: local
738
+ });
739
+ } else bindings.exports.set(nameOf(specifier.exported), { local });
740
+ }
741
+ } else if (statement.type === "ExportAllDeclaration") {
742
+ const file = statement.exportKind === "type" ? void 0 : localFile(statement.source.value);
743
+ if (!file) continue;
744
+ if (statement.exported) bindings.exports.set(nameOf(statement.exported), {
745
+ file,
746
+ imported: "*"
747
+ });
748
+ else bindings.exportAll.push(file);
749
+ } else if (statement.type === "ExportDefaultDeclaration") {
750
+ declare("default", statement.declaration);
751
+ bindings.exports.set("default", { local: "default" });
752
+ const declaration = statement.declaration;
753
+ if ((declaration.type === "FunctionDeclaration" || declaration.type === "ClassDeclaration") && declaration.id) declare(declaration.id.name, declaration);
754
+ } else readDeclaration(statement, false);
755
+ return bindings;
756
+ }
757
+ /**
758
+ * Reads what `needs` reaches in `module`: the plugin factories that its reached code calls, and what it needs from the
759
+ * local modules it imports. The whole module counts for the Definition. In an imported module, only the exports that
760
+ * the importer uses count, with the declarations and imports that they use.
761
+ */
762
+ function readModuleNeeds(module, needs) {
763
+ const bindings = readModuleBindings(module);
679
764
  const plugins = /* @__PURE__ */ new Set();
680
- if (locals.size) walk(module.program, (node) => {
681
- if (node.type === "CallExpression" && node.callee.type === "Identifier" && locals.has(node.callee.name)) plugins.add(locals.get(node.callee.name));
765
+ const imports = [];
766
+ const need = (file, imported) => imports.push([file, imported === "*" ? "all" : /* @__PURE__ */ new Set([imported])]);
767
+ const collectCalls = (node, references) => walk(node, (child) => {
768
+ if (child.type === "ImportDeclaration") return false;
769
+ if (child.type === "CallExpression" && child.callee.type === "Identifier" && bindings.pluginFactories.has(child.callee.name)) plugins.add(bindings.pluginFactories.get(child.callee.name));
770
+ if (child.type === "Identifier") references?.add(child.name);
682
771
  });
772
+ if (needs === "all") {
773
+ const references = /* @__PURE__ */ new Set();
774
+ collectCalls(module.program, references);
775
+ for (const [name, { file, imported }] of bindings.imports) if (references.has(name)) need(file, imported);
776
+ for (const [, target] of bindings.exports) if ("file" in target) need(target.file, target.imported);
777
+ return {
778
+ plugins: [...plugins],
779
+ imports
780
+ };
781
+ }
782
+ const locals = [];
783
+ for (const name of needs) {
784
+ const target = bindings.exports.get(name);
785
+ if (!target) for (const file of bindings.exportAll) need(file, name);
786
+ else if ("file" in target) need(target.file, target.imported);
787
+ else locals.push(target.local);
788
+ }
789
+ const reached = /* @__PURE__ */ new Set();
790
+ for (let local = locals.pop(); local !== void 0; local = locals.pop()) {
791
+ if (reached.has(local)) continue;
792
+ reached.add(local);
793
+ const imported = bindings.imports.get(local);
794
+ if (imported) need(imported.file, imported.imported);
795
+ const references = /* @__PURE__ */ new Set();
796
+ for (const declaration of bindings.declarations.get(local) ?? []) collectCalls(declaration, references);
797
+ for (const reference of references) if (bindings.declarations.has(reference) || bindings.imports.has(reference)) locals.push(reference);
798
+ }
799
+ return {
800
+ plugins: [...plugins],
801
+ imports
802
+ };
803
+ }
804
+ /**
805
+ * The plugins of `AuthSchemaPlugin` that the Definition module calls, and that the local modules it imports call in
806
+ * the exports it uses, such as `stripe()` in `src/server/auth-plugins.ts` that returns the plugins of `server/auth.ts`.
807
+ */
808
+ function readDefinitionSchemaPlugins(definition) {
809
+ const plugins = /* @__PURE__ */ new Set();
810
+ const modules = /* @__PURE__ */ new Map([[definition.file, definition]]);
811
+ const done = /* @__PURE__ */ new Map();
812
+ const queue = [[definition.file, "all"]];
813
+ for (let item = queue.shift(); item; item = queue.shift()) {
814
+ const [file, needs] = item;
815
+ const previous = done.get(file);
816
+ if (previous === "all") continue;
817
+ const fresh = needs === "all" ? "all" : new Set([...needs].filter((name) => !previous?.has(name)));
818
+ if (fresh !== "all" && !fresh.size) continue;
819
+ done.set(file, fresh === "all" ? "all" : /* @__PURE__ */ new Set([...previous ?? [], ...fresh]));
820
+ let module = modules.get(file);
821
+ if (!module) modules.set(file, module = scanModule(readFileSync(file, "utf8"), file));
822
+ const result = readModuleNeeds(module, fresh);
823
+ for (const plugin of result.plugins) plugins.add(plugin);
824
+ queue.push(...result.imports);
825
+ }
683
826
  return [...plugins].sort();
684
827
  }
685
828
  const authFieldTypes = /* @__PURE__ */ new Set([
@@ -768,15 +911,33 @@ function readReturnedObject(callback) {
768
911
  const value = returned ? unwrapExpression(returned) : void 0;
769
912
  return value?.type === "ObjectExpression" ? value : void 0;
770
913
  }
914
+ /** The value of a top-level `const name = value`, exported or not. */
915
+ function topLevelConstValue(module, name) {
916
+ for (const statement of module.program.body) {
917
+ const declaration = statement.type === "ExportNamedDeclaration" ? statement.declaration : statement;
918
+ if (declaration?.type !== "VariableDeclaration" || declaration.kind !== "const") continue;
919
+ for (const declarator of declaration.declarations) if (declarator.id.type === "Identifier" && declarator.id.name === name) return declarator.init ? unwrapExpression(declarator.init) : void 0;
920
+ }
921
+ }
922
+ /**
923
+ * The exported `defineAuth()` call: `export default defineAuth(...)`, or `export default auth` after a top-level
924
+ * `const auth: AuthDefinition<...> = defineAuth(...)`. A composite TypeScript project needs that annotation when it
925
+ * cannot write the inferred type of the Definition (TS7056), as with the Better Auth `apiKey()` plugin.
926
+ */
927
+ function exportedDefineAuthCall(module) {
928
+ const exported = defaultExportExpression(module);
929
+ const call = exported?.type === "Identifier" ? topLevelConstValue(module, exported.name) : exported;
930
+ return call?.type === "CallExpression" && call.callee.type === "Identifier" && call.callee.name === "defineAuth" ? call : void 0;
931
+ }
771
932
  function readDefinitionObjectBody(file) {
772
933
  const module = scanModule(readFileSync(file, "utf8"), file);
773
934
  const authDatabase = readAuthDatabaseImports(module);
774
- const call = defaultExportExpression(module);
775
- if (call?.type !== "CallExpression" || call.callee.type !== "Identifier" || call.callee.name !== "defineAuth") return;
935
+ const call = exportedDefineAuthCall(module);
936
+ if (!call) return;
776
937
  const argument = call.arguments[0];
777
938
  if (argument === void 0 || argument.type === "SpreadElement") return;
778
939
  const options = unwrapExpression(argument);
779
- const plugins = readAuthSchemaPlugins(module);
940
+ const plugins = readDefinitionSchemaPlugins(module);
780
941
  if (hasObjectProperty(objectLiteral(options) ?? readReturnedObject(options), "runtime")) throw authErrorDiagnostics.AUTH_C0039({ message: "`defineAuth()` no longer takes `runtime`. Pass one callback that returns all options, so no option replaces another." });
781
942
  if (options.type === "ObjectExpression") {
782
943
  assertAuthDatabasePlacement(options, options, authDatabase);
@@ -789,6 +950,7 @@ function readDefinitionObjectBody(file) {
789
950
  }
790
951
  const returned = readReturnedObject(options);
791
952
  assertAuthDatabasePlacement(options, returned, authDatabase);
953
+ assertOneReturnWithPages(options);
792
954
  return returned === void 0 ? void 0 : {
793
955
  authDatabase,
794
956
  body: returned,
@@ -931,6 +1093,50 @@ function readAuthAccessSignInConfig(body) {
931
1093
  }
932
1094
  return resolved;
933
1095
  }
1096
+ /** The build reads only the first return of a callback, so access.pages in any other branch would go unguarded. */
1097
+ function assertOneReturnWithPages(options) {
1098
+ if (options.type !== "ArrowFunctionExpression" || options.body.type !== "BlockStatement") return;
1099
+ const returned = [];
1100
+ walk(options.body, (node) => {
1101
+ if (node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression") return false;
1102
+ if (node.type === "ReturnStatement") returned.push(node.argument);
1103
+ });
1104
+ const declaresPages = (argument) => {
1105
+ const body = objectLiteral(argument ? unwrapExpression(argument) : void 0);
1106
+ if (!hasObjectProperty(body, "access")) return false;
1107
+ const access = readObjectPropertyValue(body, "access");
1108
+ const object = objectLiteral(access && unwrapExpression(access));
1109
+ return !object || hasObjectProperty(object, "pages");
1110
+ };
1111
+ if (returned.length > 1 && returned.some(declaresPages)) throw authErrorDiagnostics.AUTH_PAGE_ROUTES_INVALID({ message: "A `defineAuth()` callback that sets access.pages must have one `return`, so that the build reads the same pages as every request." });
1112
+ }
1113
+ /** `access.pages`, which the Nuxt module turns into route rules at build time, like `access.signIn`. */
1114
+ function readAuthAccessPagesConfig(body) {
1115
+ if (!hasObjectProperty(body, "access")) return {};
1116
+ const expression = readObjectPropertyValue(body, "access");
1117
+ const unwrapped = expression && unwrapExpression(expression);
1118
+ if (unwrapped?.type === "Identifier" && unwrapped.name === "undefined") return {};
1119
+ const access = objectLiteral(unwrapped);
1120
+ if (!access || readObjectEntries(access).some((entry) => !entry.key)) throw authErrorDiagnostics.AUTH_PAGE_ROUTES_INVALID({ message: "`defineAuth()` access must be an inline object with only static keys, without a spread, so that the build can read access.pages." });
1121
+ if (!hasObjectProperty(access, "pages")) return {};
1122
+ const value = readObjectPropertyValue(access, "pages");
1123
+ const object = objectLiteral(value && unwrapExpression(value));
1124
+ const entries = readObjectEntries(object);
1125
+ if (!object || entries.some((entry) => !entry.key)) throw authErrorDiagnostics.AUTH_PAGE_ROUTES_INVALID({ message: "`defineAuth()` access.pages must be an inline object literal with string keys, such as `{ '/dashboard/**': 'user' }`." });
1126
+ const pages = Object.fromEntries(entries.map(({ key, value }) => [key, value && staticValue(value)]));
1127
+ assertAuthPages(pages);
1128
+ return { pages };
1129
+ }
1130
+ /** `components.prefix`, which the Nuxt module reads at build time to name `<AuthPermission>`, like `basePath`. */
1131
+ function readAuthComponentsConfig(body) {
1132
+ if (!hasObjectProperty(body, "components")) return;
1133
+ const components = objectLiteral(readObjectPropertyValue(body, "components"));
1134
+ if (!components || readObjectEntries(components).some((entry) => entry.key !== "prefix")) throw authErrorDiagnostics.AUTH_COMPONENTS_INVALID();
1135
+ if (!hasObjectProperty(components, "prefix")) return;
1136
+ const prefix = staticString(readObjectPropertyValue(components, "prefix"));
1137
+ if (!prefix?.trim() || prefix !== prefix.trim()) throw authErrorDiagnostics.AUTH_COMPONENTS_INVALID();
1138
+ return { prefix };
1139
+ }
934
1140
  /** The `authDatabase()` call of the `database` option, or undefined for any other value. */
935
1141
  function readAuthDatabaseCall(body, authDatabase) {
936
1142
  const value = readObjectPropertyValue(body, "database");
@@ -992,14 +1198,17 @@ function resolveAuthViteConfig(options, rootDir = process.cwd(), discovery = {})
992
1198
  const basePath = normalizeAuthBasePath(readStaticStringProperty(body, "basePath", "basePath"));
993
1199
  const abilities = discoverAuthAbilities(rootDir, discovery);
994
1200
  const publicRoutes = readAuthAccessPublicConfig(body);
1201
+ const components = readAuthComponentsConfig(body);
995
1202
  return {
996
1203
  ...abilities ? { abilities } : {},
997
1204
  access: {
998
1205
  routes: readAuthAccessRoutesConfig(body),
999
1206
  ...publicRoutes.length ? { public: publicRoutes } : {},
1000
- ...readAuthAccessSignInConfig(body)
1207
+ ...readAuthAccessSignInConfig(body),
1208
+ ...readAuthAccessPagesConfig(body)
1001
1209
  },
1002
1210
  basePath,
1211
+ ...components ? { components } : {},
1003
1212
  definition,
1004
1213
  rootDir,
1005
1214
  route: readAuthRouteConfig(body),
@@ -1007,8 +1216,7 @@ function resolveAuthViteConfig(options, rootDir = process.cwd(), discovery = {})
1007
1216
  ...!definitionObject.callback && !["database", "preset"].some((key) => hasObjectProperty(body, key)) ? { implicitMemory: true } : {}
1008
1217
  };
1009
1218
  }
1010
- //#endregion
1011
- //#region src/deployment-env.ts
1219
+ // src/deployment-env.ts
1012
1220
  const owners = ["auth"];
1013
1221
  /**
1014
1222
  * The variables that Auth reads on the deployed host. Better Auth signs with the first Better Auth secret that is
@@ -1052,8 +1260,7 @@ function authDeploymentEnv(config) {
1052
1260
  }
1053
1261
  ];
1054
1262
  }
1055
- //#endregion
1056
- //#region src/table-names.ts
1263
+ // src/table-names.ts
1057
1264
  /**
1058
1265
  * The schema keys of the Auth schemas and their SQL names. Its own module, so the Vite plugin lists the tables without
1059
1266
  * loading Drizzle or the schema module.
@@ -1077,8 +1284,7 @@ const authTableNames = {
1077
1284
  invitation: "invitation",
1078
1285
  passkey: "passkey"
1079
1286
  };
1080
- //#endregion
1081
- //#region src/existing-tables.ts
1287
+ // src/existing-tables.ts
1082
1288
  function isRecord(value) {
1083
1289
  return typeof value === "object" && value !== null && !Array.isArray(value);
1084
1290
  }
@@ -1140,8 +1346,7 @@ function readAuthExistingTables(migrationsDir, tableNames) {
1140
1346
  }
1141
1347
  return tables;
1142
1348
  }
1143
- //#endregion
1144
- //#region src/vite.ts
1349
+ // src/vite.ts
1145
1350
  const AUTH_ABILITIES_ID = "#vitehub/auth/abilities";
1146
1351
  const AUTH_CLIENT_ID = "#vitehub/auth/client";
1147
1352
  const AUTH_DEFINITION_ID = "#vitehub/auth/definition";
@@ -1226,14 +1431,17 @@ function createAuthNitroConfig(plugin, options) {
1226
1431
  }
1227
1432
  function renderAuthDefinitionModule(config, options = { serverEnv: false }) {
1228
1433
  if (!config) return "export const definition = undefined\nexport const getAuthApp = () => undefined\nexport default definition\n";
1434
+ const runtimeServer = JSON.stringify(options.runtimeServer ?? privateAuthImport(options.importBase ?? authPackageName, "runtime/server"));
1229
1435
  return [
1230
1436
  `import definition from ${JSON.stringify(config.definition.handler)}`,
1231
1437
  options.testMode ? "export const getAuthApp = () => undefined" : "export { useNitroApp as getAuthApp } from \"nitro/app\"",
1232
1438
  ...options.serverEnv ? [
1233
- `import { setAuthRuntimeEnvResolver } from ${JSON.stringify(privateAuthImport(options.importBase ?? authPackageName, "runtime/server"))}`,
1439
+ `import { setAuthRuntimeEnvResolver } from ${runtimeServer}`,
1234
1440
  `import { useServerEnv } from ${JSON.stringify(envServerModuleId)}`,
1235
1441
  "setAuthRuntimeEnvResolver(useServerEnv, definition)"
1236
1442
  ] : [],
1443
+ `import { checkBuiltAuthPages } from ${runtimeServer}`,
1444
+ `checkBuiltAuthPages(definition, ${JSON.stringify(config.access.pages ?? {})})`,
1237
1445
  "export { definition }",
1238
1446
  "export default definition",
1239
1447
  ""
@@ -1241,7 +1449,10 @@ function renderAuthDefinitionModule(config, options = { serverEnv: false }) {
1241
1449
  }
1242
1450
  async function writeNuxtAuthDefinition(root, config) {
1243
1451
  const file = resolve(resolveViteHubProjectRoot(root), ".vitehub/auth/definition.ts");
1244
- await writeFileIfChanged(file, renderAuthDefinitionModule(config));
1452
+ await writeFileIfChanged(file, renderAuthDefinitionModule(config, {
1453
+ runtimeServer: ownModule(import.meta.url, "runtime/server"),
1454
+ serverEnv: false
1455
+ }));
1245
1456
  return file;
1246
1457
  }
1247
1458
  /** Private Auth entries of the distribution. */
@@ -1258,7 +1469,7 @@ function renderAuthServerModule(options = {}) {
1258
1469
  return [
1259
1470
  `export * from ${JSON.stringify(serverImport)}`,
1260
1471
  `export { default } from ${JSON.stringify(serverImport)}`,
1261
- `export { createAuthAccessHandler } from ${JSON.stringify(privateAuthImport(importBase, "internal/server"))}`,
1472
+ `export { createAuthAccessHandler, findVerifiedAuthUserId } from ${JSON.stringify(privateAuthImport(importBase, "internal/server"))}`,
1262
1473
  ""
1263
1474
  ].join("\n");
1264
1475
  }
@@ -1322,7 +1533,9 @@ function renderAuthAmbientTypes(options = { serverEnv: false }) {
1322
1533
  /**
1323
1534
  * The declaration of the virtual module. It stays out of a file with imports, which would make it an augmentation of
1324
1535
  * a module that must already resolve. When only the bundler resolves `#vitehub/auth/server`, the tsconfig would not
1325
- * find it and the types of everything that imports the Auth handlers would be `any`.
1536
+ * find it and the types of everything that imports the Auth handlers would be `any`. An `export ... from` in this
1537
+ * block must name a package: TypeScript drops one with a file path (TS2439), and the private entry of `vite-hub` is a
1538
+ * file path. A `typeof import()` type takes any path.
1326
1539
  */
1327
1540
  function renderAuthServerTypes(importBase = authPackageName) {
1328
1541
  const serverImport = `${importBase}/server`;
@@ -1330,7 +1543,8 @@ function renderAuthServerTypes(importBase = authPackageName) {
1330
1543
  `declare module ${JSON.stringify(AUTH_SERVER_ID)} {`,
1331
1544
  ` export * from ${JSON.stringify(serverImport)}`,
1332
1545
  ` export { default } from ${JSON.stringify(serverImport)}`,
1333
- ` export { createAuthAccessHandler } from ${JSON.stringify(privateAuthImport(importBase, "internal/server"))}`,
1546
+ ` export const createAuthAccessHandler: typeof import(${JSON.stringify(privateAuthImport(importBase, "internal/server"))}).createAuthAccessHandler`,
1547
+ ` export const findVerifiedAuthUserId: typeof import(${JSON.stringify(privateAuthImport(importBase, "internal/server"))}).findVerifiedAuthUserId`,
1334
1548
  "}",
1335
1549
  ""
1336
1550
  ].join("\n");
@@ -1598,5 +1812,4 @@ function hubAuth(options, internalOptions = {}) {
1598
1812
  }
1599
1813
  };
1600
1814
  }
1601
- //#endregion
1602
- export { AUTH_VITE_PLUGIN_NAME as a, writeNuxtAuthDefinition as c, resolveNuxtServerDirs as d, resolveViteHubProjectRoot as f, AUTH_SERVER_ID as i, resolveAuthViteConfig as l, AUTH_CLIENT_ID as n, createAuthNitroConfig as o, AUTH_DEFINITION_ID as r, hubAuth as s, AUTH_ABILITIES_ID as t, authAbilitiesCandidates as u };
1815
+ export { AUTH_VITE_PLUGIN_NAME as a, writeNuxtAuthDefinition as c, cachingRuleNames as d, createCachingRouteRuleFinder as f, resolveViteHubProjectRoot as h, AUTH_SERVER_ID as i, resolveAuthViteConfig as l, resolveNuxtServerDirs as m, AUTH_CLIENT_ID as n, createAuthNitroConfig as o, methodOrder as p, AUTH_DEFINITION_ID as r, hubAuth as s, AUTH_ABILITIES_ID as t, authAbilitiesCandidates as u };