@vite-hub/auth 0.0.2 → 0.0.3
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.
- package/dist/vite.js +14 -12
- package/package.json +4 -4
package/dist/vite.js
CHANGED
|
@@ -500,24 +500,24 @@ const authDefinitionExtensions = [
|
|
|
500
500
|
".mjs",
|
|
501
501
|
".cjs"
|
|
502
502
|
];
|
|
503
|
-
function authDefinitionCandidates(rootDir) {
|
|
504
|
-
return authDefinitionExtensions.flatMap((extension) => [{
|
|
505
|
-
handler: resolve(
|
|
503
|
+
function authDefinitionCandidates(rootDir, serverDirs = [resolve(rootDir, "server")]) {
|
|
504
|
+
return authDefinitionExtensions.flatMap((extension) => [...serverDirs.map((serverDir) => ({
|
|
505
|
+
handler: resolve(serverDir, `auth${extension}`),
|
|
506
506
|
name: "default",
|
|
507
507
|
source: "server-auth"
|
|
508
|
-
}, {
|
|
508
|
+
})), {
|
|
509
509
|
handler: resolve(rootDir, `server.auth${extension}`),
|
|
510
510
|
name: "default",
|
|
511
511
|
source: "server-auth-suffix"
|
|
512
512
|
}]);
|
|
513
513
|
}
|
|
514
|
-
function discoverAuthDefinitions(rootDir) {
|
|
515
|
-
const definitions = authDefinitionCandidates(rootDir).filter((definition) => existsSync(definition.handler));
|
|
514
|
+
function discoverAuthDefinitions(rootDir, options = {}) {
|
|
515
|
+
const definitions = authDefinitionCandidates(rootDir, options.serverDirs).filter((definition) => existsSync(definition.handler));
|
|
516
516
|
if (definitions.length > 1) throw new Error(["[vitehub] Only one Auth Definition is allowed. Found:", ...definitions.map((definition) => ` - ${definition.handler}`)].join("\n"));
|
|
517
517
|
return definitions;
|
|
518
518
|
}
|
|
519
|
-
function discoverAuthDefinition(rootDir) {
|
|
520
|
-
return discoverAuthDefinitions(rootDir)[0];
|
|
519
|
+
function discoverAuthDefinition(rootDir, options = {}) {
|
|
520
|
+
return discoverAuthDefinitions(rootDir, options)[0];
|
|
521
521
|
}
|
|
522
522
|
//#endregion
|
|
523
523
|
//#region src/config.ts
|
|
@@ -697,9 +697,9 @@ function readAuthSecondaryStorageConfig(body, allowRuntimeValue = false) {
|
|
|
697
697
|
})()
|
|
698
698
|
};
|
|
699
699
|
}
|
|
700
|
-
function resolveAuthViteConfig(options, rootDir = process.cwd()) {
|
|
700
|
+
function resolveAuthViteConfig(options, rootDir = process.cwd(), discovery = {}) {
|
|
701
701
|
if (options === false) return;
|
|
702
|
-
const definition = discoverAuthDefinition(rootDir);
|
|
702
|
+
const definition = discoverAuthDefinition(rootDir, discovery);
|
|
703
703
|
if (!definition) return;
|
|
704
704
|
const definitionObject = readDefinitionObjectBody(definition.handler);
|
|
705
705
|
if (typeof definitionObject === "undefined") throw new TypeError("`defineAuth()` options must be an inline object literal.");
|
|
@@ -902,13 +902,14 @@ function hubAuth(options) {
|
|
|
902
902
|
const importBase = options?.importBase ?? authPackageName;
|
|
903
903
|
let resolved;
|
|
904
904
|
let runtimeConfig;
|
|
905
|
+
let serverDirs;
|
|
905
906
|
let serverEnv = false;
|
|
906
907
|
function resolvedOptions() {
|
|
907
908
|
return resolved?.auth ?? options;
|
|
908
909
|
}
|
|
909
910
|
function refreshRuntimeConfig() {
|
|
910
911
|
if (!resolved) return;
|
|
911
|
-
runtimeConfig = resolveAuthViteConfig(resolvedOptions(), resolved.root);
|
|
912
|
+
runtimeConfig = resolveAuthViteConfig(resolvedOptions(), resolved.root, { serverDirs });
|
|
912
913
|
resetAuth();
|
|
913
914
|
return runtimeConfig;
|
|
914
915
|
}
|
|
@@ -921,7 +922,8 @@ function hubAuth(options) {
|
|
|
921
922
|
},
|
|
922
923
|
config(config) {
|
|
923
924
|
const configRoot = config.root || process.cwd();
|
|
924
|
-
|
|
925
|
+
serverDirs = config["__vitehubServerDirs"] ?? serverDirs;
|
|
926
|
+
const authConfig = resolveAuthViteConfig(config.auth ?? options, configRoot, { serverDirs });
|
|
925
927
|
const nitro = mergeNitroAuthHandler(config.nitro, authConfig);
|
|
926
928
|
const hasNitroHandlers = Boolean(authConfig && (authConfig.route !== false || authConfig.access.routes.length > 0));
|
|
927
929
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vite-hub/auth",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Better Auth-powered authentication primitives and Vite integration for ViteHub.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"auth",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"better-auth": "^1.6.23",
|
|
43
|
-
"@vite-hub/runtime": "0.0.
|
|
43
|
+
"@vite-hub/runtime": "0.0.3"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/node": "^24.13.3",
|
|
@@ -50,11 +50,11 @@
|
|
|
50
50
|
"vite-plus": "^0.1.24",
|
|
51
51
|
"vitest": "^4.1.4",
|
|
52
52
|
"@vite-hub/internal": "0.0.1",
|
|
53
|
-
"@vite-hub/agent": "0.0.
|
|
53
|
+
"@vite-hub/agent": "0.0.3"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
56
|
"vite": ">=8.0.0",
|
|
57
|
-
"@vite-hub/agent": "0.0.
|
|
57
|
+
"@vite-hub/agent": "0.0.3"
|
|
58
58
|
},
|
|
59
59
|
"peerDependenciesMeta": {
|
|
60
60
|
"@vite-hub/agent": {
|