@farm.js/auth 0.1.0-beta.104 → 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/runtime.d.ts CHANGED
@@ -29,5 +29,25 @@ export declare function migrateFarmAuth(): Promise<void>;
29
29
  * from Farm's own table declarations.
30
30
  */
31
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[];
32
52
  export {};
33
53
  //# sourceMappingURL=runtime.d.ts.map
@@ -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;IACb,IAAI,EAAE,aAAa,GAAG,YAAY,CAAC;CACpC;AAED,UAAU,iBAAiB;IACzB,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC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C,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
@@ -127,7 +127,8 @@ async function createBetterAuthOptions(config, options, runtimeOptions = {}) {
127
127
  }
128
128
  return {
129
129
  appName: config.appName || "Farm app",
130
- baseURL: resolveBaseURL(options.mode),
130
+ baseURL: resolveFarmAuthBaseURL(options.mode),
131
+ trustedOrigins: resolveFarmAuthTrustedOrigins(),
131
132
  basePath: config.basePath,
132
133
  secret: secret || "farm-auth-development-or-migration-secret",
133
134
  database: await createDatabase(config, options),
@@ -143,17 +144,46 @@ async function createBetterAuthOptions(config, options, runtimeOptions = {}) {
143
144
  },
144
145
  };
145
146
  }
146
- function resolveBaseURL(mode) {
147
- const configured = process.env.FARM_AUTH_URL || process.env.BETTER_AUTH_URL;
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;
148
160
  if (configured)
149
161
  return configured;
150
- if (process.env.VERCEL_URL) {
151
- return process.env.VERCEL_URL.startsWith("http")
152
- ? process.env.VERCEL_URL
153
- : `https://${process.env.VERCEL_URL}`;
154
- }
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);
155
167
  return mode === "development" ? "http://localhost:3000" : undefined;
156
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
+ }
157
187
  async function closeDatabase(database) {
158
188
  if (!database || typeof database !== "object")
159
189
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farm.js/auth",
3
- "version": "0.1.0-beta.104",
3
+ "version": "0.1.0-beta.105",
4
4
  "description": "Farm-native authentication with email/password, server helpers, and React hooks",
5
5
  "license": "MIT",
6
6
  "repository": {