@vite-hub/auth 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/README.md +49 -34
  2. package/dist/{abilities-DfAnFYwG.d.ts → abilities-CbmTAoS_.d.ts} +1 -1
  3. package/dist/abilities.d.ts +1 -1
  4. package/dist/{ability-error-CqgBrBfR.js → ability-error-IeZQBr_-.js} +1 -1
  5. package/dist/agent.js +6 -5
  6. package/dist/{auth-instance-CR6b1W80.js → auth-instance-CmDogt4D.js} +20 -13
  7. package/dist/cli.js +1 -1
  8. package/dist/{console-runtime-DTopBP-x.d.ts → console-runtime-D2ai-Et5.d.ts} +1 -1
  9. package/dist/{console-runtime-J9_Vx9pT.js → console-runtime-_LrpyCYY.js} +2 -2
  10. package/dist/console-runtime.d.ts +2 -2
  11. package/dist/console-runtime.js +1 -1
  12. package/dist/console.d.ts +1 -1
  13. package/dist/{database-options-BRNef9oy.js → database-options-DpOVjUti.js} +1 -1
  14. package/dist/{database-schema-options-ENuRMduM.js → database-schema-options-Sk-1Bvyu.js} +1 -1
  15. package/dist/database.d.ts +1 -1
  16. package/dist/database.js +3 -3
  17. package/dist/{definition-CqQMcDEK.js → definition-BCaLA9kW.js} +146 -8
  18. package/dist/{error-diagnostics-C8XtVz0i.js → error-diagnostics-Dymr-S_n.js} +40 -4
  19. package/dist/{events-ByzenEVj.js → events-DCfuicoo.js} +6 -14
  20. package/dist/forward.js +1 -1
  21. package/dist/index.d.ts +3 -8
  22. package/dist/index.js +3 -3
  23. package/dist/internal/server.d.ts +3 -3
  24. package/dist/internal/server.js +6 -858
  25. package/dist/mcp-config-DRRlCAWN.js +18 -0
  26. package/dist/mcp-token-CpxLyl_p.js +222 -0
  27. package/dist/mcp.d.ts +96 -85
  28. package/dist/mcp.js +3 -184
  29. package/dist/{members-D9lfaEO_.js → members-DdlsS8kJ.js} +5 -5
  30. package/dist/nuxt.d.ts +15 -2
  31. package/dist/nuxt.js +9 -12
  32. package/dist/{presets-BGZi6Dfu.d.ts → presets-CHndEv5i.d.ts} +3 -4
  33. package/dist/presets.d.ts +2 -2
  34. package/dist/presets.js +3 -13
  35. package/dist/runtime/console.d.ts +1 -1
  36. package/dist/runtime/console.js +2 -2
  37. package/dist/runtime/empty-abilities.d.ts +1 -1
  38. package/dist/runtime/empty-definition.d.ts +2 -1
  39. package/dist/runtime/empty-definition.js +2 -1
  40. package/dist/runtime/nuxt.js +2 -2
  41. package/dist/runtime/server.d.ts +1 -1
  42. package/dist/runtime/vue-nuxt.js +15 -7
  43. package/dist/schema.js +1 -1
  44. package/dist/server-BG_MFd4q.js +980 -0
  45. package/dist/{server-C0qnKN2W.d.ts → server-BM-RSf1T.d.ts} +76 -15
  46. package/dist/{server-bQGzVQ--.d.ts → server-C8TlOrSy.d.ts} +3 -3
  47. package/dist/server.d.ts +2 -2
  48. package/dist/server.js +3 -3
  49. package/dist/{session-cookies-BbH3UR2m.js → session-cookies-DVzjOKc7.js} +69 -5
  50. package/dist/{set-cookie-C8NOhdRE.js → set-cookie-DmqWq6kj.js} +1 -1
  51. package/dist/{shared-BwcdRGxD.js → shared-DRtfuFsV.js} +1 -1
  52. package/dist/{table-specs-8gq_FCaq.js → table-specs-CURphR3n.js} +1 -1
  53. package/dist/test.d.ts +1 -1
  54. package/dist/test.js +2 -2
  55. package/dist/{types-CNaeH2Fd.d.ts → types-CruflEFI.d.ts} +62 -43
  56. package/dist/{vite-CV400XXY.js → vite-Dy0Xhq4H.js} +195 -149
  57. package/dist/vite.d.ts +2 -1
  58. package/dist/vite.js +2 -2
  59. package/dist/vue.d.ts +4 -19
  60. package/dist/vue.js +6 -9
  61. package/package.json +9 -9
@@ -1,17 +1,132 @@
1
- import { t as authErrorDiagnostics } from "./error-diagnostics-C8XtVz0i.js";
1
+ import { t as authErrorDiagnostics } from "./error-diagnostics-Dymr-S_n.js";
2
2
  import { n as isRecordOrFunction, t as isRecord$1 } from "./object-Da1zyPCR.js";
3
3
  import { i as resetAuth } from "./runtime-state-ojQCzKOc.js";
4
4
  import { t as invariant } from "./invariant-D8_xBqmZ.js";
5
5
  import { r as resolveAccessRoutePath, t as accessRouteSyntaxError } from "./application-path-DuTpfGFj.js";
6
- import { t as normalizeAuthBasePath } from "./shared-BwcdRGxD.js";
7
- import { a as authDatabaseSchemaError, i as authDatabasePlacementError, n as authDatabaseAdditionalFieldsError, o as authMemoryDatabaseError, t as assertAuthDatabaseIdStrategy } from "./database-options-BRNef9oy.js";
8
- import { i as resolveAuthTableSpecs, n as authSqlName } from "./table-specs-8gq_FCaq.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";
9
9
  import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
10
10
  import { basename, dirname, join, parse, relative, resolve } from "node:path";
11
11
  import { fileURLToPath } from "node:url";
12
12
  import { tmpdir } from "node:os";
13
13
  import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
14
14
  import { parseSync } from "vite";
15
+ //#region ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs
16
+ const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
17
+ function normalizeWindowsPath(input = "") {
18
+ if (!input) return input;
19
+ return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
20
+ }
21
+ const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
22
+ const _DRIVE_LETTER_RE = /^[A-Za-z]:$/;
23
+ const _ROOT_FOLDER_RE = /^\/([A-Za-z]:)?$/;
24
+ function cwd() {
25
+ if (typeof process !== "undefined" && typeof process.cwd === "function") return process.cwd().replace(/\\/g, "/");
26
+ return "/";
27
+ }
28
+ const resolve$1 = function(...arguments_) {
29
+ arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
30
+ let resolvedPath = "";
31
+ let resolvedAbsolute = false;
32
+ for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
33
+ const path = index >= 0 ? arguments_[index] : cwd();
34
+ if (!path || path.length === 0) continue;
35
+ resolvedPath = `${path}/${resolvedPath}`;
36
+ resolvedAbsolute = isAbsolute(path);
37
+ }
38
+ resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
39
+ if (resolvedAbsolute && !isAbsolute(resolvedPath)) return `/${resolvedPath}`;
40
+ return resolvedPath.length > 0 ? resolvedPath : ".";
41
+ };
42
+ function normalizeString(path, allowAboveRoot) {
43
+ let res = "";
44
+ let lastSegmentLength = 0;
45
+ let lastSlash = -1;
46
+ let dots = 0;
47
+ let char = null;
48
+ for (let index = 0; index <= path.length; ++index) {
49
+ if (index < path.length) char = path[index];
50
+ else if (char === "/") break;
51
+ else char = "/";
52
+ if (char === "/") {
53
+ if (lastSlash === index - 1 || dots === 1);
54
+ else if (dots === 2) {
55
+ if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
56
+ if (res.length > 2) {
57
+ const lastSlashIndex = res.lastIndexOf("/");
58
+ if (lastSlashIndex === -1) {
59
+ res = "";
60
+ lastSegmentLength = 0;
61
+ } else {
62
+ res = res.slice(0, lastSlashIndex);
63
+ lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
64
+ }
65
+ lastSlash = index;
66
+ dots = 0;
67
+ continue;
68
+ } else if (res.length > 0) {
69
+ res = "";
70
+ lastSegmentLength = 0;
71
+ lastSlash = index;
72
+ dots = 0;
73
+ continue;
74
+ }
75
+ }
76
+ if (allowAboveRoot) {
77
+ res += res.length > 0 ? "/.." : "..";
78
+ lastSegmentLength = 2;
79
+ }
80
+ } else {
81
+ if (res.length > 0) res += `/${path.slice(lastSlash + 1, index)}`;
82
+ else res = path.slice(lastSlash + 1, index);
83
+ lastSegmentLength = index - lastSlash - 1;
84
+ }
85
+ lastSlash = index;
86
+ dots = 0;
87
+ } else if (char === "." && dots !== -1) ++dots;
88
+ else dots = -1;
89
+ }
90
+ return res;
91
+ }
92
+ const isAbsolute = function(p) {
93
+ return _IS_ABSOLUTE_RE.test(p);
94
+ };
95
+ const relative$1 = function(from, to) {
96
+ const _from = resolve$1(from).replace(_ROOT_FOLDER_RE, "$1").split("/");
97
+ const _to = resolve$1(to).replace(_ROOT_FOLDER_RE, "$1").split("/");
98
+ if (_to[0][1] === ":" && _from[0][1] === ":" && _from[0] !== _to[0]) return _to.join("/");
99
+ const _fromCopy = [..._from];
100
+ for (const segment of _fromCopy) {
101
+ if (_to[0] !== segment) break;
102
+ _from.shift();
103
+ _to.shift();
104
+ }
105
+ return [..._from.map(() => ".."), ..._to].join("/");
106
+ };
107
+ const dirname$1 = function(p) {
108
+ const segments = normalizeWindowsPath(p).replace(/\/$/, "").split("/").slice(0, -1);
109
+ if (segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0])) segments[0] += "/";
110
+ return segments.join("/") || (isAbsolute(p) ? "/" : ".");
111
+ };
112
+ //#endregion
113
+ //#region ../internal/src/inspect.ts
114
+ function relativeDefinitionFile(projectRoot, file) {
115
+ return relative$1(projectRoot, file).replaceAll("\\", "/");
116
+ }
117
+ /** Summarizes Definitions that have no owner-specific fields. */
118
+ function summarizeDefinitions(projectRoot, definitions, fallbackSource) {
119
+ return definitions.map((definition) => ({
120
+ fields: [],
121
+ file: relativeDefinitionFile(projectRoot, definition.handler),
122
+ name: definition.name,
123
+ source: definition.source || fallbackSource
124
+ }));
125
+ }
126
+ const secretKeyPattern = /secret|token|passw(?:or)?d|credential|api[-_\s]?key|private[-_\s]?key|authorization|cookie|signature|dsn|connection[-_\s]?string/i;
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
+ 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
15
130
  //#region ../internal/src/build/vite.ts
16
131
  const generatedViteHubFilesPattern = "**/.vitehub/**";
17
132
  const projectRootDirectoryMarkers = [
@@ -119,104 +234,6 @@ function hasProjectRootFileMarker(root, markers) {
119
234
  return false;
120
235
  }
121
236
  //#endregion
122
- //#region ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs
123
- const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
124
- function normalizeWindowsPath(input = "") {
125
- if (!input) return input;
126
- return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
127
- }
128
- const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
129
- const _DRIVE_LETTER_RE = /^[A-Za-z]:$/;
130
- const _ROOT_FOLDER_RE = /^\/([A-Za-z]:)?$/;
131
- function cwd() {
132
- if (typeof process !== "undefined" && typeof process.cwd === "function") return process.cwd().replace(/\\/g, "/");
133
- return "/";
134
- }
135
- const resolve$1 = function(...arguments_) {
136
- arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
137
- let resolvedPath = "";
138
- let resolvedAbsolute = false;
139
- for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
140
- const path = index >= 0 ? arguments_[index] : cwd();
141
- if (!path || path.length === 0) continue;
142
- resolvedPath = `${path}/${resolvedPath}`;
143
- resolvedAbsolute = isAbsolute(path);
144
- }
145
- resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
146
- if (resolvedAbsolute && !isAbsolute(resolvedPath)) return `/${resolvedPath}`;
147
- return resolvedPath.length > 0 ? resolvedPath : ".";
148
- };
149
- function normalizeString(path, allowAboveRoot) {
150
- let res = "";
151
- let lastSegmentLength = 0;
152
- let lastSlash = -1;
153
- let dots = 0;
154
- let char = null;
155
- for (let index = 0; index <= path.length; ++index) {
156
- if (index < path.length) char = path[index];
157
- else if (char === "/") break;
158
- else char = "/";
159
- if (char === "/") {
160
- if (lastSlash === index - 1 || dots === 1);
161
- else if (dots === 2) {
162
- if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
163
- if (res.length > 2) {
164
- const lastSlashIndex = res.lastIndexOf("/");
165
- if (lastSlashIndex === -1) {
166
- res = "";
167
- lastSegmentLength = 0;
168
- } else {
169
- res = res.slice(0, lastSlashIndex);
170
- lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
171
- }
172
- lastSlash = index;
173
- dots = 0;
174
- continue;
175
- } else if (res.length > 0) {
176
- res = "";
177
- lastSegmentLength = 0;
178
- lastSlash = index;
179
- dots = 0;
180
- continue;
181
- }
182
- }
183
- if (allowAboveRoot) {
184
- res += res.length > 0 ? "/.." : "..";
185
- lastSegmentLength = 2;
186
- }
187
- } else {
188
- if (res.length > 0) res += `/${path.slice(lastSlash + 1, index)}`;
189
- else res = path.slice(lastSlash + 1, index);
190
- lastSegmentLength = index - lastSlash - 1;
191
- }
192
- lastSlash = index;
193
- dots = 0;
194
- } else if (char === "." && dots !== -1) ++dots;
195
- else dots = -1;
196
- }
197
- return res;
198
- }
199
- const isAbsolute = function(p) {
200
- return _IS_ABSOLUTE_RE.test(p);
201
- };
202
- const relative$1 = function(from, to) {
203
- const _from = resolve$1(from).replace(_ROOT_FOLDER_RE, "$1").split("/");
204
- const _to = resolve$1(to).replace(_ROOT_FOLDER_RE, "$1").split("/");
205
- if (_to[0][1] === ":" && _from[0][1] === ":" && _from[0] !== _to[0]) return _to.join("/");
206
- const _fromCopy = [..._from];
207
- for (const segment of _fromCopy) {
208
- if (_to[0] !== segment) break;
209
- _from.shift();
210
- _to.shift();
211
- }
212
- return [..._from.map(() => ".."), ..._to].join("/");
213
- };
214
- const dirname$1 = function(p) {
215
- const segments = normalizeWindowsPath(p).replace(/\/$/, "").split("/").slice(0, -1);
216
- if (segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0])) segments[0] += "/";
217
- return segments.join("/") || (isAbsolute(p) ? "/" : ".");
218
- };
219
- //#endregion
220
237
  //#region ../internal/src/build/paths.ts
221
238
  function resolveRuntimeModule(packageDir, modulePath) {
222
239
  const distFile = resolve$1(packageDir, "dist", `${modulePath}.js`);
@@ -282,23 +299,6 @@ async function writeFileIfChanged(file, contents) {
282
299
  await writeFile(file, contents, "utf8");
283
300
  }
284
301
  //#endregion
285
- //#region ../internal/src/inspect.ts
286
- function relativeDefinitionFile(projectRoot, file) {
287
- return relative$1(projectRoot, file).replaceAll("\\", "/");
288
- }
289
- /** Summarizes Definitions that have no owner-specific fields. */
290
- function summarizeDefinitions(projectRoot, definitions, fallbackSource) {
291
- return definitions.map((definition) => ({
292
- fields: [],
293
- file: relativeDefinitionFile(projectRoot, definition.handler),
294
- name: definition.name,
295
- source: definition.source || fallbackSource
296
- }));
297
- }
298
- const secretKeyPattern = /secret|token|passw(?:or)?d|credential|api[-_\s]?key|private[-_\s]?key|authorization|cookie|signature|dsn|connection[-_\s]?string/i;
299
- 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");
300
- new RegExp(String.raw`\b([\w-]*(?:${secretKeyPattern.source})[\w-]*["']?\s*[:=]\s*)(?!\[redacted\](?=$|[\s,;}&]))(?:"(?:\\[^\r\n]|[^"\\\r\n])*"|'(?:\\[^\r\n]|[^'\\\r\n])*'|[^\s,;&#&]+)`, "gi");
301
- //#endregion
302
302
  //#region ../internal/src/contributions.ts
303
303
  function isThenable(value) {
304
304
  return typeof value.then === "function";
@@ -407,6 +407,30 @@ async function assertNoCachedAccessRoutes(routes, routeRules, baseURL = "/", pub
407
407
  }
408
408
  }
409
409
  //#endregion
410
+ //#region ../internal/src/build/ast-walk.ts
411
+ /** The oxc parser grammar for a file, from its extension. Defaults to TypeScript. */
412
+ function moduleLanguage(file) {
413
+ if (/\.(?:c|m)?tsx$/i.test(file)) return "tsx";
414
+ if (/\.(?:c|m)?jsx$/i.test(file)) return "jsx";
415
+ if (/\.(?:c|m)?js$/i.test(file)) return "js";
416
+ return "ts";
417
+ }
418
+ function isNode(value) {
419
+ return typeof value === "object" && value !== null && "type" in value && typeof value.type === "string";
420
+ }
421
+ /** Visits `node` and its descendants. Return `false` from `visit` to skip the children of a node. */
422
+ function walk(node, visit, parent) {
423
+ if (visit(node, parent) === false) return;
424
+ const fields = node;
425
+ for (const key in fields) {
426
+ const child = fields[key];
427
+ if (typeof child !== "object" || child === null || key === "parent") continue;
428
+ if (Array.isArray(child)) {
429
+ for (const item of child) if (isNode(item)) walk(item, visit, node);
430
+ } else if (isNode(child)) walk(child, visit, node);
431
+ }
432
+ }
433
+ //#endregion
410
434
  //#region ../internal/src/build/scan-module.ts
411
435
  /**
412
436
  * Reads facts from JavaScript and TypeScript modules at build and dev time. The scanner parses each module once with
@@ -415,16 +439,10 @@ async function assertNoCachedAccessRoutes(routes, routeRules, baseURL = "/", pub
415
439
  */
416
440
  /** The value of an expression that the scanner cannot read without running the module. */
417
441
  const dynamic = Symbol("dynamic");
418
- function languageOf(file) {
419
- if (/\.(?:c|m)?tsx$/i.test(file)) return "tsx";
420
- if (/\.(?:c|m)?jsx$/i.test(file)) return "jsx";
421
- if (/\.(?:c|m)?js$/i.test(file)) return "js";
422
- return "ts";
423
- }
424
442
  /** Parses a module once. `file` selects the grammar from its extension and defaults to TypeScript. */
425
443
  function scanModule(source, file = "module.ts") {
426
444
  const result = parseSync(file, source, {
427
- lang: languageOf(file),
445
+ lang: moduleLanguage(file),
428
446
  preserveParens: false,
429
447
  sourceType: "module"
430
448
  });
@@ -436,21 +454,6 @@ function scanModule(source, file = "module.ts") {
436
454
  source
437
455
  };
438
456
  }
439
- function isNode(value) {
440
- return typeof value === "object" && value !== null && "type" in value && typeof value.type === "string";
441
- }
442
- /** Visits `node` and its descendants. Return `false` from `visit` to skip the children of a node. */
443
- function walk(node, visit, parent) {
444
- if (visit(node, parent) === false) return;
445
- const fields = node;
446
- for (const key in fields) {
447
- const child = fields[key];
448
- if (typeof child !== "object" || child === null || key === "parent") continue;
449
- if (Array.isArray(child)) {
450
- for (const item of child) if (isNode(item)) walk(item, visit, node);
451
- } else if (isNode(child)) walk(child, visit, node);
452
- }
453
- }
454
457
  /** Removes parentheses, `as`, `satisfies`, `!`, and `<T>` assertions around an expression. */
455
458
  function unwrapExpression(node) {
456
459
  while (node.type === "ParenthesizedExpression" || node.type === "TSAsExpression" || node.type === "TSSatisfiesExpression" || node.type === "TSNonNullExpression" || node.type === "TSTypeAssertion") node = node.expression;
@@ -907,6 +910,27 @@ function readAuthAccessPublicConfig(body) {
907
910
  return route;
908
911
  });
909
912
  }
913
+ /** `access.signIn` and `access.afterSignIn`, which the Nuxt page guard reads at build time, like `basePath`. */
914
+ function readAuthAccessSignInConfig(body) {
915
+ const access = objectLiteral(readObjectPropertyValue(body, "access"));
916
+ if (!access) return {};
917
+ const resolved = {};
918
+ if (hasObjectProperty(access, "signIn")) {
919
+ const value = readObjectPropertyValue(access, "signIn");
920
+ const page = staticString(value);
921
+ const provider = objectLiteral(value);
922
+ if (provider && hasObjectProperty(provider, "callbackURL")) throw authErrorDiagnostics.AUTH_SIGN_IN_CALLBACK_URL_MOVED();
923
+ if (provider) resolved.signIn = { provider: true };
924
+ else if (page?.startsWith("/") && !/^\/[/\\]/.test(page)) resolved.signIn = { page };
925
+ else throw authErrorDiagnostics.AUTH_C0028({ message: "`defineAuth()` access.signIn must be an inline path that starts with one `/`, such as `'/login'`, or an inline object, such as `{ provider: 'github' }`." });
926
+ }
927
+ if (hasObjectProperty(access, "afterSignIn")) {
928
+ const afterSignIn = staticString(readObjectPropertyValue(access, "afterSignIn"));
929
+ if (!afterSignIn?.startsWith("/") || /^\/[/\\]/.test(afterSignIn)) throw authErrorDiagnostics.AUTH_AFTER_SIGN_IN_INVALID();
930
+ resolved.afterSignIn = afterSignIn;
931
+ }
932
+ return resolved;
933
+ }
910
934
  /** The `authDatabase()` call of the `database` option, or undefined for any other value. */
911
935
  function readAuthDatabaseCall(body, authDatabase) {
912
936
  const value = readObjectPropertyValue(body, "database");
@@ -972,7 +996,8 @@ function resolveAuthViteConfig(options, rootDir = process.cwd(), discovery = {})
972
996
  ...abilities ? { abilities } : {},
973
997
  access: {
974
998
  routes: readAuthAccessRoutesConfig(body),
975
- ...publicRoutes.length ? { public: publicRoutes } : {}
999
+ ...publicRoutes.length ? { public: publicRoutes } : {},
1000
+ ...readAuthAccessSignInConfig(body)
976
1001
  },
977
1002
  basePath,
978
1003
  definition,
@@ -1200,9 +1225,10 @@ function createAuthNitroConfig(plugin, options) {
1200
1225
  return viteConfig.nitro;
1201
1226
  }
1202
1227
  function renderAuthDefinitionModule(config, options = { serverEnv: false }) {
1203
- if (!config) return "export const definition = undefined\nexport default definition\n";
1228
+ if (!config) return "export const definition = undefined\nexport const getAuthApp = () => undefined\nexport default definition\n";
1204
1229
  return [
1205
1230
  `import definition from ${JSON.stringify(config.definition.handler)}`,
1231
+ options.testMode ? "export const getAuthApp = () => undefined" : "export { useNitroApp as getAuthApp } from \"nitro/app\"",
1206
1232
  ...options.serverEnv ? [
1207
1233
  `import { setAuthRuntimeEnvResolver } from ${JSON.stringify(privateAuthImport(options.importBase ?? authPackageName, "runtime/server"))}`,
1208
1234
  `import { useServerEnv } from ${JSON.stringify(envServerModuleId)}`,
@@ -1213,6 +1239,11 @@ function renderAuthDefinitionModule(config, options = { serverEnv: false }) {
1213
1239
  ""
1214
1240
  ].join("\n");
1215
1241
  }
1242
+ async function writeNuxtAuthDefinition(root, config) {
1243
+ const file = resolve(resolveViteHubProjectRoot(root), ".vitehub/auth/definition.ts");
1244
+ await writeFileIfChanged(file, renderAuthDefinitionModule(config));
1245
+ return file;
1246
+ }
1216
1247
  /** Private Auth entries of the distribution. */
1217
1248
  function privateAuthImport(importBase, entry) {
1218
1249
  return importBase === "vite-hub/auth" ? ownModule(import.meta.url, entry) : `${importBase}/${entry}`;
@@ -1225,17 +1256,22 @@ function renderAuthServerModule(options = {}) {
1225
1256
  const importBase = options.importBase ?? authPackageName;
1226
1257
  const serverImport = `${importBase}/server`;
1227
1258
  return [
1228
- `export * from ${JSON.stringify(privateAuthImport(importBase, "internal/server"))}`,
1259
+ `export * from ${JSON.stringify(serverImport)}`,
1229
1260
  `export { default } from ${JSON.stringify(serverImport)}`,
1261
+ `export { createAuthAccessHandler } from ${JSON.stringify(privateAuthImport(importBase, "internal/server"))}`,
1230
1262
  ""
1231
1263
  ].join("\n");
1232
1264
  }
1233
1265
  function renderAuthRouteHandler() {
1234
1266
  return [`export { default } from ${JSON.stringify(AUTH_SERVER_ID)}`, ""].join("\n");
1235
1267
  }
1268
+ /** `access.public`, and the Auth route: sign-in and the OAuth callback must work without a session. */
1269
+ function accessPublicRoutes(config) {
1270
+ return [authRoutePattern(config.basePath), ...config.access.public ?? []];
1271
+ }
1236
1272
  function renderAuthAccessMiddlewareHandler(config, importBase = authPackageName) {
1237
1273
  const routes = JSON.stringify(config?.access.routes ?? []);
1238
- const publicRoutes = config?.access.public?.length ? `, ${JSON.stringify(config.access.public)}` : "";
1274
+ const publicRoutes = config?.access.routes.length ? `, ${JSON.stringify(accessPublicRoutes(config))}` : "";
1239
1275
  return [
1240
1276
  `import { createLazyAuthAccessHandler } from ${JSON.stringify(privateAuthImport(importBase, "runtime/server"))}`,
1241
1277
  "",
@@ -1261,6 +1297,10 @@ function renderAuthAmbientTypes(options = { serverEnv: false }) {
1261
1297
  ...options.client ? [`client: typeof import(${JSON.stringify(options.client)}).default`] : []
1262
1298
  ];
1263
1299
  const registry = entries.length ? [`interface AuthRegistry { ${entries.join("; ")} }`] : [];
1300
+ if (options.definition) {
1301
+ const session = `Pick<import(${JSON.stringify(options.importBase ?? authPackageName)}).AuthAuthorization<{ definition: typeof import(${JSON.stringify(options.definition)}).default }>, "user" | "session">`;
1302
+ registry.push(`interface AuthRegistry { sessionResult: ${session} }`);
1303
+ }
1264
1304
  if (options.serverEnv) return [
1265
1305
  `import type { ServerEnv } from ${JSON.stringify(envServerModuleId)}`,
1266
1306
  "",
@@ -1288,8 +1328,9 @@ function renderAuthServerTypes(importBase = authPackageName) {
1288
1328
  const serverImport = `${importBase}/server`;
1289
1329
  return [
1290
1330
  `declare module ${JSON.stringify(AUTH_SERVER_ID)} {`,
1291
- ` export * from ${JSON.stringify(privateAuthImport(importBase, "internal/server"))}`,
1331
+ ` export * from ${JSON.stringify(serverImport)}`,
1292
1332
  ` export { default } from ${JSON.stringify(serverImport)}`,
1333
+ ` export { createAuthAccessHandler } from ${JSON.stringify(privateAuthImport(importBase, "internal/server"))}`,
1293
1334
  "}",
1294
1335
  ""
1295
1336
  ].join("\n");
@@ -1301,6 +1342,7 @@ async function refreshAuthGeneratedFiles(root, config, options = {}) {
1301
1342
  abilities: config?.abilities && typeImportSpecifier(dirname(authAmbientTypesPath(root)), config.abilities),
1302
1343
  client: options.client && typeImportSpecifier(dirname(authAmbientTypesPath(root)), options.client),
1303
1344
  definition: config && typeImportSpecifier(dirname(authAmbientTypesPath(root)), config.definition.handler),
1345
+ importBase: options.importBase,
1304
1346
  serverEnv: Boolean(options.serverEnv)
1305
1347
  })),
1306
1348
  writeFileIfChanged(authServerTypesPath(root), renderAuthServerTypes(options.importBase)),
@@ -1360,7 +1402,8 @@ function mergeNitroAuthHandler(value, config, dev) {
1360
1402
  if (!dev && config.implicitMemory) modules.push(memoryDatabaseGuard);
1361
1403
  if (modules.length || Array.isArray(merged.modules)) merged.modules = modules;
1362
1404
  if (config.access.routes.length > 0) {
1363
- const { routes, public: publicRoutes = [] } = config.access;
1405
+ const { routes } = config.access;
1406
+ const publicRoutes = accessPublicRoutes(config);
1364
1407
  merged.modules = [...modules, {
1365
1408
  name: cachedAccessRouteGuardName,
1366
1409
  setup(nitro) {
@@ -1373,6 +1416,8 @@ function mergeNitroAuthHandler(value, config, dev) {
1373
1416
  return merged;
1374
1417
  }
1375
1418
  function hubAuth(options, internalOptions = {}) {
1419
+ const configured = options;
1420
+ if (configured !== void 0 && configured !== false) throw authErrorDiagnostics.AUTH_REDIRECTS_MOVED();
1376
1421
  const importBase = internalOptions.importBase ?? authPackageName;
1377
1422
  let resolved;
1378
1423
  let runtimeConfig;
@@ -1545,7 +1590,8 @@ function hubAuth(options, internalOptions = {}) {
1545
1590
  if (id === RESOLVED_AUTH_CLIENT_ID) return "export default undefined\n";
1546
1591
  if (id === RESOLVED_AUTH_DEFINITION_ID) return renderAuthDefinitionModule(runtimeConfig, {
1547
1592
  importBase,
1548
- serverEnv
1593
+ serverEnv,
1594
+ testMode: resolved?.mode === "test"
1549
1595
  });
1550
1596
  if (id === RESOLVED_AUTH_SERVER_ID) return renderAuthServerModule({ importBase });
1551
1597
  }
@@ -1553,4 +1599,4 @@ function hubAuth(options, internalOptions = {}) {
1553
1599
  };
1554
1600
  }
1555
1601
  //#endregion
1556
- export { AUTH_VITE_PLUGIN_NAME as a, resolveAuthViteConfig as c, resolveViteHubProjectRoot as d, AUTH_SERVER_ID as i, authAbilitiesCandidates as l, AUTH_CLIENT_ID as n, createAuthNitroConfig as o, AUTH_DEFINITION_ID as r, hubAuth as s, AUTH_ABILITIES_ID as t, resolveNuxtServerDirs as u };
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 };
package/dist/vite.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /// <reference path="./host-declarations.d.ts" />
2
- import { S as AuthOptions, V as ResolvedAuthViteConfig } from "./types-CNaeH2Fd.js";
2
+ import { C as AuthOptions, H as ResolvedAuthViteConfig } from "./types-CruflEFI.js";
3
3
  import { n as ViteHubCliPluginMetadata } from "./cli-ubYJpAL_.js";
4
4
  import { Plugin } from "vite";
5
5
  //#region ../internal/src/inspect.d.ts
@@ -160,5 +160,6 @@ export declare function createAuthNitroConfig(plugin: AuthVitePlugin, options: {
160
160
  interface InternalAuthModuleOptions {
161
161
  importBase?: string;
162
162
  }
163
+ export declare function writeNuxtAuthDefinition(root: string, config: ResolvedAuthViteConfig): Promise<string>;
163
164
  export declare function hubAuth(options?: AuthOptions, internalOptions?: InternalAuthModuleOptions): AuthVitePlugin;
164
165
  //#endregion
package/dist/vite.js CHANGED
@@ -1,2 +1,2 @@
1
- import { a as AUTH_VITE_PLUGIN_NAME, c as resolveAuthViteConfig, i as AUTH_SERVER_ID, n as AUTH_CLIENT_ID, o as createAuthNitroConfig, r as AUTH_DEFINITION_ID, s as hubAuth, t as AUTH_ABILITIES_ID } from "./vite-CV400XXY.js";
2
- export { AUTH_ABILITIES_ID, AUTH_CLIENT_ID, AUTH_DEFINITION_ID, AUTH_SERVER_ID, AUTH_VITE_PLUGIN_NAME, createAuthNitroConfig, hubAuth, resolveAuthViteConfig };
1
+ import { a as AUTH_VITE_PLUGIN_NAME, c as writeNuxtAuthDefinition, i as AUTH_SERVER_ID, l as resolveAuthViteConfig, n as AUTH_CLIENT_ID, o as createAuthNitroConfig, r as AUTH_DEFINITION_ID, s as hubAuth, t as AUTH_ABILITIES_ID } from "./vite-Dy0Xhq4H.js";
2
+ export { AUTH_ABILITIES_ID, AUTH_CLIENT_ID, AUTH_DEFINITION_ID, AUTH_SERVER_ID, AUTH_VITE_PLUGIN_NAME, createAuthNitroConfig, hubAuth, resolveAuthViteConfig, writeNuxtAuthDefinition };
package/dist/vue.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  /// <reference path="./host-declarations.d.ts" />
2
- import { b as AuthFor, g as AuthDefinition } from "./types-CNaeH2Fd.js";
3
- import { a as AbilityRefusal, i as AbilityName, t as AbilityArgs } from "./abilities-DfAnFYwG.js";
2
+ import { g as AuthDefinition, x as AuthFor } from "./types-CruflEFI.js";
3
+ import { a as AbilityRefusal, i as AbilityName, t as AbilityArgs } from "./abilities-CbmTAoS_.js";
4
4
  import { n as AbilityErrorData } from "./ability-error-DcgChwCN.js";
5
- import { BetterAuthClientOptions, SessionQueryParams } from "better-auth";
6
- import { ComputedRef, DeepReadonly, Ref, VNode } from "vue";
5
+ import { BetterAuthClientOptions } from "better-auth";
6
+ import { ComputedRef, VNode } from "vue";
7
7
  import { inferAdditionalFields } from "better-auth/client/plugins";
8
8
  import { BetterFetchError, VueAuthClient, VueAuthClient as VueAuthClient$1, createAuthClient as createAuthClient$1 } from "better-auth/vue";
9
9
  //#region src/nuxt-bridge.d.ts
@@ -184,21 +184,6 @@ export declare const authClient: RegisteredAuthClient;
184
184
  /** Provide the app's configured client to Auth composables and `<Can>` in descendant components. */
185
185
  export declare function provideAuthClient(client: AuthClientLike): void;
186
186
  export declare function useAuthClient(): typeof authClient;
187
- export interface AuthSessionState<Client extends AuthClientLike = typeof authClient> {
188
- data: Client["$Infer"]["Session"] | null;
189
- error: BetterFetchError | null;
190
- isPending: boolean;
191
- isRefetching: boolean;
192
- refetch: (queryParams?: {
193
- query?: SessionQueryParams;
194
- }) => Promise<void>;
195
- }
196
- type AuthSessionRef<Client extends AuthClientLike = typeof authClient> = DeepReadonly<Ref<AuthSessionState<Client>>>;
197
- /**
198
- * The session of `client`. Every call for the same client in the same app returns the same ref, so a list of
199
- * components that call it costs one watcher. In Nuxt, the page guard reads the session into the same ref.
200
- */
201
- export declare function useSession<Client extends AuthClientLike = typeof authClient>(client?: Client): AuthSessionRef<Client>;
202
187
  type ClientSession<Client extends AuthClientLike> = Client["$Infer"]["Session"];
203
188
  /** Better Auth's `signOut()` of `Client`. */
204
189
  type ClientSignOut<Client extends AuthClientLike> = Extract<Client["signOut"], (...args: never) => unknown>;
package/dist/vue.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { i as resolveAuthMountPath } from "./application-path-DuTpfGFj.js";
2
- import { n as checkAbility, t as AbilityError } from "./ability-error-CqgBrBfR.js";
2
+ import { n as checkAbility, t as AbilityError } from "./ability-error-IeZQBr_-.js";
3
3
  import { a as setRequestFetchResolver, i as setNuxtErrorFactory, n as setDefaultAuthBasePath, o as setSessionSeedResolver, r as setNuxtAppResolver, s as setSignOutHandler, t as authNuxtBridge } from "./nuxt-bridge-Cl988STZ.js";
4
4
  import abilities from "#vitehub/auth/abilities";
5
5
  import { computed, defineComponent, effectScope, getCurrentInstance, getCurrentScope, inject, onScopeDispose, onServerPrefetch, provide, shallowRef, watch } from "vue";
@@ -415,11 +415,8 @@ function useAuthClient() {
415
415
  const nuxtApp = authNuxtBridge.nuxtAppResolver?.() || instance?.appContext.config.globalProperties.$nuxt;
416
416
  return client ?? nuxtApp?.$vitehubAuthClient ?? authClient;
417
417
  }
418
- /**
419
- * The session of `client`. Every call for the same client in the same app returns the same ref, so a list of
420
- * components that call it costs one watcher. In Nuxt, the page guard reads the session into the same ref.
421
- */
422
- function useSession(client = useAuthClient()) {
418
+ /** The session state of `client`, which `useUserSession()`, `useAbility()`, and the page guard share. */
419
+ function sessionState(client = useAuthClient()) {
423
420
  return sessionStore(client).state;
424
421
  }
425
422
  /**
@@ -554,7 +551,7 @@ async function authorizedUser(client, state) {
554
551
  * await authorize("posts.edit", loadedPost)
555
552
  */
556
553
  function useAbility(client = useAuthClient()) {
557
- const state = useSession(client);
554
+ const state = sessionState(client);
558
555
  const allows = (name, args) => {
559
556
  const refusal = abilityRefusal(state.value, name, args);
560
557
  return refusal === void 0 ? void 0 : refusal === null;
@@ -598,7 +595,7 @@ const abilityProps = {
598
595
  };
599
596
  /** The refusal of the rule that the props name. It follows the session, and is `undefined` while `pending` is `true`. */
600
597
  function usePropsRefusal(props) {
601
- const state = useSession();
598
+ const state = sessionState();
602
599
  return computed(() => {
603
600
  if (props.pending) return void 0;
604
601
  const args = props.args ?? (props.with === void 0 ? [] : [props.with]);
@@ -656,4 +653,4 @@ const Cannot = defineComponent({
656
653
  }
657
654
  });
658
655
  //#endregion
659
- export { Can, Cannot, authClient, createAuthClient, defineAuthClient, loadAuthClient, onSignOut, provideAuthClient, setDefaultAuthBasePath, setNuxtAppResolver, setNuxtErrorFactory, setRequestFetchResolver, setSessionSeedResolver, setSignOutHandler, useAbility, useAuthClient, useSession, useUserSession };
656
+ export { Can, Cannot, authClient, createAuthClient, defineAuthClient, loadAuthClient, onSignOut, provideAuthClient, setDefaultAuthBasePath, setNuxtAppResolver, setNuxtErrorFactory, setRequestFetchResolver, setSessionSeedResolver, setSignOutHandler, useAbility, useAuthClient, useUserSession };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vite-hub/auth",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "Better Auth-powered authentication primitives and Vite integration for ViteHub.",
5
5
  "keywords": [
6
6
  "auth",
@@ -144,9 +144,9 @@
144
144
  "dependencies": {
145
145
  "@noble/hashes": "^2.2.0",
146
146
  "@types/node": "^24.19.1",
147
- "@vite-hub/env": "0.3.1",
148
- "@vite-hub/runtime": "0.3.1",
149
- "@vite-hub/web-container": "0.3.1",
147
+ "@vite-hub/env": "0.4.0",
148
+ "@vite-hub/runtime": "0.4.0",
149
+ "@vite-hub/web-container": "0.4.0",
150
150
  "better-auth": "^1.7.15",
151
151
  "h3": "^2.0.8",
152
152
  "nostics": "1.4.0",
@@ -162,8 +162,8 @@
162
162
  "@types/json-schema": "^7.0.15",
163
163
  "@types/mdast": "^4.0.4",
164
164
  "@types/node": "^24.19.1",
165
- "@vite-hub/agent": "0.3.1",
166
- "@vite-hub/database": "0.3.1",
165
+ "@vite-hub/agent": "0.4.0",
166
+ "@vite-hub/database": "0.4.0",
167
167
  "@vite-hub/internal": "0.0.1",
168
168
  "bun-types": "^1.4.3",
169
169
  "happy-dom": "20.14.5",
@@ -184,8 +184,8 @@
184
184
  "@better-auth/oauth-provider": "^1.7.15",
185
185
  "@types/json-schema": "^7.0.15",
186
186
  "@types/mdast": "^4.0.4",
187
- "@vite-hub/agent": "0.3.1",
188
- "@vite-hub/database": "0.3.1",
187
+ "@vite-hub/agent": "0.4.0",
188
+ "@vite-hub/database": "0.4.0",
189
189
  "nitro": "3.0.261102-rc || ^3.0.261103-rc",
190
190
  "vite": ">=8.0.0",
191
191
  "vue": "^3.5.0",
@@ -209,7 +209,7 @@
209
209
  }
210
210
  },
211
211
  "engines": {
212
- "node": ">=22.18.0"
212
+ "node": ">=24.15.0"
213
213
  },
214
214
  "scripts": {
215
215
  "build": "vp pack",