handzon-core 0.12.0 → 0.12.2
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/package.json +1 -1
- package/src/server/auth/config.ts +22 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "handzon-core",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.2",
|
|
4
4
|
"description": "Core framework for Handzon — layouts, components, content + AI libs, and server runtime (handlers, DB, auth, migration runner) consumed by Handzon scaffolds.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -24,6 +24,12 @@ interface AuthConfigOptions {
|
|
|
24
24
|
* builds and for `pnpm build` on a fresh checkout without a database.
|
|
25
25
|
*/
|
|
26
26
|
db: Parameters<typeof DrizzleAdapter>[0] | null;
|
|
27
|
+
/**
|
|
28
|
+
* Override auth-astro's route prefix when a fronting proxy rewrites
|
|
29
|
+
* paths before the request reaches the Handzon app. Defaults to
|
|
30
|
+
* Astro's configured `base` plus `/api/auth`.
|
|
31
|
+
*/
|
|
32
|
+
authPrefix?: string;
|
|
27
33
|
}
|
|
28
34
|
|
|
29
35
|
/**
|
|
@@ -56,7 +62,14 @@ function resolveAuthUrl(): string | undefined {
|
|
|
56
62
|
return undefined;
|
|
57
63
|
}
|
|
58
64
|
|
|
59
|
-
|
|
65
|
+
function resolveAuthPrefix(authPrefix?: string): string {
|
|
66
|
+
if (authPrefix) return authPrefix;
|
|
67
|
+
const base = import.meta.env.BASE_URL;
|
|
68
|
+
const normalizedBase = base === "/" ? "" : base.replace(/\/$/, "");
|
|
69
|
+
return `${normalizedBase}/api/auth`;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function createAuthConfig({ db, authPrefix }: AuthConfigOptions) {
|
|
60
73
|
// Auth.js v5 reads `AUTH_URL` from process.env on each request, so
|
|
61
74
|
// we resolve once and write it back. Idempotent: if AUTH_URL was
|
|
62
75
|
// already a full URL, this is a no-op aside from the trailing-slash
|
|
@@ -66,13 +79,20 @@ export function createAuthConfig({ db }: AuthConfigOptions) {
|
|
|
66
79
|
process.env.AUTH_URL = resolvedUrl;
|
|
67
80
|
}
|
|
68
81
|
|
|
82
|
+
const prefix = resolveAuthPrefix(authPrefix);
|
|
83
|
+
|
|
69
84
|
if (!db) {
|
|
70
85
|
// No database → no adapter → no providers. auth-astro logs a warning
|
|
71
86
|
// and any sign-in attempt fails gracefully instead of crashing the
|
|
72
87
|
// build.
|
|
73
|
-
return defineConfig({ providers: [] });
|
|
88
|
+
return defineConfig({ prefix, providers: [] });
|
|
74
89
|
}
|
|
75
90
|
return defineConfig({
|
|
91
|
+
// auth-astro defaults to /api/auth, but Astro apps mounted with
|
|
92
|
+
// `base` receive requests at /<base>/api/auth. Use the same base
|
|
93
|
+
// that powers app links and API calls so the catch-all auth route
|
|
94
|
+
// returns a Response instead of falling through with undefined.
|
|
95
|
+
prefix,
|
|
76
96
|
adapter: DrizzleAdapter(db, {
|
|
77
97
|
usersTable: users,
|
|
78
98
|
accountsTable: accounts,
|