@farm.js/auth 0.1.0-beta.103 → 0.1.0-beta.105
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/internal.d.ts +1 -0
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +4 -1
- package/dist/runtime.d.ts +26 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +52 -10
- package/package.json +1 -1
package/dist/internal.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ interface FarmAuthIntegration {
|
|
|
18
18
|
}
|
|
19
19
|
export declare function createFarmAuthIntegration(config: ResolvedFarmAuthConfig, options: FarmAuthIntegrationOptions): FarmAuthIntegration;
|
|
20
20
|
export declare function migrateFarmAuth(): Promise<void>;
|
|
21
|
+
export declare function compileFarmAuthMigration(): Promise<string>;
|
|
21
22
|
export declare function disposeFarmAuth(): Promise<void>;
|
|
22
23
|
export {};
|
|
23
24
|
//# sourceMappingURL=internal.d.ts.map
|
package/dist/internal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AASzD,UAAU,0BAA0B;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,aAAa,GAAG,YAAY,CAAC;CACpC;AAED,UAAU,mBAAmB;IAC3B,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,WAAW,CAAC;IAClB,QAAQ,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAA;KAAE,CAAC;IACjD,MAAM,EAAE,KAAK,CAAC;QACZ,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAClC,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;KAC9C,CAAC,CAAC;CACJ;AAED,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,sBAAsB,EAC9B,OAAO,EAAE,0BAA0B,GAClC,mBAAmB,CAmBrB;AAED,wBAAsB,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC,CAErD;AAED,wBAAsB,wBAAwB,IAAI,OAAO,CAAC,MAAM,CAAC,CAEhE;AAED,wBAAsB,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC,CAErD"}
|
package/dist/internal.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { configureFarmAuth, disposeFarmAuth as runDispose, getFarmAuthRuntime, migrateFarmAuth as runMigration, } from "./runtime.js";
|
|
1
|
+
import { configureFarmAuth, disposeFarmAuth as runDispose, getFarmAuthRuntime, migrateFarmAuth as runMigration, compileFarmAuthMigration as runCompileMigration, } from "./runtime.js";
|
|
2
2
|
export function createFarmAuthIntegration(config, options) {
|
|
3
3
|
configureFarmAuth(config, options);
|
|
4
4
|
return {
|
|
@@ -21,6 +21,9 @@ export function createFarmAuthIntegration(config, options) {
|
|
|
21
21
|
export async function migrateFarmAuth() {
|
|
22
22
|
await runMigration();
|
|
23
23
|
}
|
|
24
|
+
export async function compileFarmAuthMigration() {
|
|
25
|
+
return runCompileMigration();
|
|
26
|
+
}
|
|
24
27
|
export async function disposeFarmAuth() {
|
|
25
28
|
await runDispose();
|
|
26
29
|
}
|
package/dist/runtime.d.ts
CHANGED
|
@@ -23,5 +23,31 @@ export declare function getFarmAuthRequest(request?: Request): Request;
|
|
|
23
23
|
*/
|
|
24
24
|
export declare function disposeFarmAuth(): Promise<void>;
|
|
25
25
|
export declare function migrateFarmAuth(): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* The statements `migrateFarmAuth` would run, for review before applying them.
|
|
28
|
+
* Better Auth owns the schema, so the sql comes from its migrator rather than
|
|
29
|
+
* from Farm's own table declarations.
|
|
30
|
+
*/
|
|
31
|
+
export declare function compileFarmAuthMigration(): Promise<string>;
|
|
32
|
+
/**
|
|
33
|
+
* The origin Better Auth signs cookies and validates requests against.
|
|
34
|
+
*
|
|
35
|
+
* Better Auth trusts the baseURL's own origin and rejects everything else
|
|
36
|
+
* with INVALID_ORIGIN, so this has to resolve to the host users actually
|
|
37
|
+
* visit. Vercel exposes two: `VERCEL_URL` is unique per deployment
|
|
38
|
+
* (`my-app-a1b2c3.vercel.app`) while `VERCEL_PROJECT_PRODUCTION_URL` is the
|
|
39
|
+
* project's canonical domain. Pinning a production deployment to its
|
|
40
|
+
* per-deployment hostname rejects every request arriving on the real domain,
|
|
41
|
+
* so production prefers the canonical one and previews keep their own URL.
|
|
42
|
+
*/
|
|
43
|
+
export declare function resolveFarmAuthBaseURL(mode: "development" | "production", env?: NodeJS.ProcessEnv): string | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Hosts that stay valid alongside the base URL.
|
|
46
|
+
*
|
|
47
|
+
* A production deployment is still reachable at its own deployment hostname,
|
|
48
|
+
* and previews get a fresh one per build, so both are trusted explicitly
|
|
49
|
+
* rather than leaving direct deployment-URL access broken.
|
|
50
|
+
*/
|
|
51
|
+
export declare function resolveFarmAuthTrustedOrigins(env?: NodeJS.ProcessEnv): string[];
|
|
26
52
|
export {};
|
|
27
53
|
//# sourceMappingURL=runtime.d.ts.map
|
package/dist/runtime.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAMzD,UAAU,sBAAsB;IAC9B,IAAI,EAAE,MAAM,CAAC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AAC,iBAAiB,CAAC,CA6BrE;AAED,wBAAgB,kBAAkB,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAU7D;AAED;;;;;;GAMG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC,CASrD;AAED,wBAAsB,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC,CAIrD;AAED;;;;GAIG;AACH,wBAAsB,wBAAwB,IAAI,OAAO,CAAC,MAAM,CAAC,CAEhE;AA4ED;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,aAAa,GAAG,YAAY,EAClC,GAAG,GAAE,MAAM,CAAC,UAAwB,GACnC,MAAM,GAAG,SAAS,CAWpB;AAED;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,MAAM,EAAE,CAM5F"}
|
package/dist/runtime.js
CHANGED
|
@@ -81,6 +81,19 @@ export async function disposeFarmAuth() {
|
|
|
81
81
|
await closeDatabase(database);
|
|
82
82
|
}
|
|
83
83
|
export async function migrateFarmAuth() {
|
|
84
|
+
await withAuthMigrations(async (migrations) => {
|
|
85
|
+
await migrations.runMigrations();
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* The statements `migrateFarmAuth` would run, for review before applying them.
|
|
90
|
+
* Better Auth owns the schema, so the sql comes from its migrator rather than
|
|
91
|
+
* from Farm's own table declarations.
|
|
92
|
+
*/
|
|
93
|
+
export async function compileFarmAuthMigration() {
|
|
94
|
+
return withAuthMigrations((migrations) => migrations.compileMigrations());
|
|
95
|
+
}
|
|
96
|
+
async function withAuthMigrations(use) {
|
|
84
97
|
const state = getState();
|
|
85
98
|
if (!state.config?.enabled || !state.options) {
|
|
86
99
|
throw new Error("Farm Auth is not enabled in farm.config.ts.");
|
|
@@ -90,8 +103,7 @@ export async function migrateFarmAuth() {
|
|
|
90
103
|
});
|
|
91
104
|
const { getMigrations } = await import("better-auth/db/migration");
|
|
92
105
|
try {
|
|
93
|
-
|
|
94
|
-
await migrations.runMigrations();
|
|
106
|
+
return await use(await getMigrations(options));
|
|
95
107
|
}
|
|
96
108
|
finally {
|
|
97
109
|
await closeDatabase(options.database);
|
|
@@ -115,7 +127,8 @@ async function createBetterAuthOptions(config, options, runtimeOptions = {}) {
|
|
|
115
127
|
}
|
|
116
128
|
return {
|
|
117
129
|
appName: config.appName || "Farm app",
|
|
118
|
-
baseURL:
|
|
130
|
+
baseURL: resolveFarmAuthBaseURL(options.mode),
|
|
131
|
+
trustedOrigins: resolveFarmAuthTrustedOrigins(),
|
|
119
132
|
basePath: config.basePath,
|
|
120
133
|
secret: secret || "farm-auth-development-or-migration-secret",
|
|
121
134
|
database: await createDatabase(config, options),
|
|
@@ -131,17 +144,46 @@ async function createBetterAuthOptions(config, options, runtimeOptions = {}) {
|
|
|
131
144
|
},
|
|
132
145
|
};
|
|
133
146
|
}
|
|
134
|
-
|
|
135
|
-
|
|
147
|
+
/**
|
|
148
|
+
* The origin Better Auth signs cookies and validates requests against.
|
|
149
|
+
*
|
|
150
|
+
* Better Auth trusts the baseURL's own origin and rejects everything else
|
|
151
|
+
* with INVALID_ORIGIN, so this has to resolve to the host users actually
|
|
152
|
+
* visit. Vercel exposes two: `VERCEL_URL` is unique per deployment
|
|
153
|
+
* (`my-app-a1b2c3.vercel.app`) while `VERCEL_PROJECT_PRODUCTION_URL` is the
|
|
154
|
+
* project's canonical domain. Pinning a production deployment to its
|
|
155
|
+
* per-deployment hostname rejects every request arriving on the real domain,
|
|
156
|
+
* so production prefers the canonical one and previews keep their own URL.
|
|
157
|
+
*/
|
|
158
|
+
export function resolveFarmAuthBaseURL(mode, env = process.env) {
|
|
159
|
+
const configured = env.FARM_AUTH_URL || env.BETTER_AUTH_URL;
|
|
136
160
|
if (configured)
|
|
137
161
|
return configured;
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
162
|
+
const vercelHost = env.VERCEL_ENV === "production"
|
|
163
|
+
? env.VERCEL_PROJECT_PRODUCTION_URL || env.VERCEL_URL
|
|
164
|
+
: env.VERCEL_URL;
|
|
165
|
+
if (vercelHost)
|
|
166
|
+
return toAbsoluteOrigin(vercelHost);
|
|
143
167
|
return mode === "development" ? "http://localhost:3000" : undefined;
|
|
144
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* Hosts that stay valid alongside the base URL.
|
|
171
|
+
*
|
|
172
|
+
* A production deployment is still reachable at its own deployment hostname,
|
|
173
|
+
* and previews get a fresh one per build, so both are trusted explicitly
|
|
174
|
+
* rather than leaving direct deployment-URL access broken.
|
|
175
|
+
*/
|
|
176
|
+
export function resolveFarmAuthTrustedOrigins(env = process.env) {
|
|
177
|
+
const origins = new Set();
|
|
178
|
+
for (const host of [env.VERCEL_URL, env.VERCEL_PROJECT_PRODUCTION_URL, env.VERCEL_BRANCH_URL]) {
|
|
179
|
+
if (host)
|
|
180
|
+
origins.add(toAbsoluteOrigin(host));
|
|
181
|
+
}
|
|
182
|
+
return [...origins];
|
|
183
|
+
}
|
|
184
|
+
function toAbsoluteOrigin(host) {
|
|
185
|
+
return host.startsWith("http://") || host.startsWith("https://") ? host : `https://${host}`;
|
|
186
|
+
}
|
|
145
187
|
async function closeDatabase(database) {
|
|
146
188
|
if (!database || typeof database !== "object")
|
|
147
189
|
return;
|