@farm.js/auth 0.1.0-beta.99 → 0.1.1-beta.1
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/client.d.ts +8 -0
- package/dist/client.d.ts.map +1 -1
- 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 +61 -10
- package/package.json +2 -2
package/dist/client.d.ts
CHANGED
|
@@ -92,6 +92,8 @@ export declare function createFarmAuthClient(options?: FarmAuthClientOptions): {
|
|
|
92
92
|
signOut: () => Promise<{
|
|
93
93
|
data: {
|
|
94
94
|
success: boolean;
|
|
95
|
+
url: string | undefined;
|
|
96
|
+
redirect: boolean | undefined;
|
|
95
97
|
};
|
|
96
98
|
error: null;
|
|
97
99
|
} | {
|
|
@@ -253,6 +255,8 @@ export declare function createFarmAuthClient(options?: FarmAuthClientOptions): {
|
|
|
253
255
|
signOut: () => Promise<{
|
|
254
256
|
data: {
|
|
255
257
|
success: boolean;
|
|
258
|
+
url: string | undefined;
|
|
259
|
+
redirect: boolean | undefined;
|
|
256
260
|
};
|
|
257
261
|
error: null;
|
|
258
262
|
} | {
|
|
@@ -334,6 +338,8 @@ export declare const getSession: () => Promise<{
|
|
|
334
338
|
}>, signOut: () => Promise<{
|
|
335
339
|
data: {
|
|
336
340
|
success: boolean;
|
|
341
|
+
url: string | undefined;
|
|
342
|
+
redirect: boolean | undefined;
|
|
337
343
|
};
|
|
338
344
|
error: null;
|
|
339
345
|
} | {
|
|
@@ -515,6 +521,8 @@ export declare const getSession: () => Promise<{
|
|
|
515
521
|
signOut: () => Promise<{
|
|
516
522
|
data: {
|
|
517
523
|
success: boolean;
|
|
524
|
+
url: string | undefined;
|
|
525
|
+
redirect: boolean | undefined;
|
|
518
526
|
};
|
|
519
527
|
error: null;
|
|
520
528
|
} | {
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAElG,wBAAgB,oBAAoB,CAAC,OAAO,GAAE,qBAA0B;oBAG/C,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oBAInB,mBAAmB
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAElG,wBAAgB,oBAAoB,CAAC,OAAO,GAAE,qBAA0B;oBAG/C,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oBAInB,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA0CilB,CAAC;;wBA9CrmB,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAInB,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmC3C;AAID,eAAO,MAAQ,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAAE,MAAM,UA3CR,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA2CT,OAAO;;;;;;;;;;;;;;;IAAE,MAAM,UAvCzB,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAuCQ,OAAO;;;;;;;;;;;;;;;;;;;;;;;;aAGkkB,CAAC;;oBA9CrmB,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oBAInB,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuCiC,CAAC;AAE9E,YAAY,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC"}
|
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;IACb,IAAI,EA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AAC,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
|
@@ -41,6 +41,15 @@ export async function getFarmAuthRuntime() {
|
|
|
41
41
|
}
|
|
42
42
|
});
|
|
43
43
|
state.runtime = runtime;
|
|
44
|
+
void runtime.catch(() => {
|
|
45
|
+
if (state.runtime === runtime) {
|
|
46
|
+
state.runtime = undefined;
|
|
47
|
+
const database = state.database;
|
|
48
|
+
state.database = undefined;
|
|
49
|
+
if (database)
|
|
50
|
+
void closeDatabase(database).catch(() => { });
|
|
51
|
+
}
|
|
52
|
+
});
|
|
44
53
|
}
|
|
45
54
|
return state.runtime;
|
|
46
55
|
}
|
|
@@ -72,6 +81,19 @@ export async function disposeFarmAuth() {
|
|
|
72
81
|
await closeDatabase(database);
|
|
73
82
|
}
|
|
74
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) {
|
|
75
97
|
const state = getState();
|
|
76
98
|
if (!state.config?.enabled || !state.options) {
|
|
77
99
|
throw new Error("Farm Auth is not enabled in farm.config.ts.");
|
|
@@ -81,8 +103,7 @@ export async function migrateFarmAuth() {
|
|
|
81
103
|
});
|
|
82
104
|
const { getMigrations } = await import("better-auth/db/migration");
|
|
83
105
|
try {
|
|
84
|
-
|
|
85
|
-
await migrations.runMigrations();
|
|
106
|
+
return await use(await getMigrations(options));
|
|
86
107
|
}
|
|
87
108
|
finally {
|
|
88
109
|
await closeDatabase(options.database);
|
|
@@ -106,7 +127,8 @@ async function createBetterAuthOptions(config, options, runtimeOptions = {}) {
|
|
|
106
127
|
}
|
|
107
128
|
return {
|
|
108
129
|
appName: config.appName || "Farm app",
|
|
109
|
-
baseURL:
|
|
130
|
+
baseURL: resolveFarmAuthBaseURL(options.mode),
|
|
131
|
+
trustedOrigins: resolveFarmAuthTrustedOrigins(),
|
|
110
132
|
basePath: config.basePath,
|
|
111
133
|
secret: secret || "farm-auth-development-or-migration-secret",
|
|
112
134
|
database: await createDatabase(config, options),
|
|
@@ -122,17 +144,46 @@ async function createBetterAuthOptions(config, options, runtimeOptions = {}) {
|
|
|
122
144
|
},
|
|
123
145
|
};
|
|
124
146
|
}
|
|
125
|
-
|
|
126
|
-
|
|
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;
|
|
127
160
|
if (configured)
|
|
128
161
|
return configured;
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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);
|
|
134
167
|
return mode === "development" ? "http://localhost:3000" : undefined;
|
|
135
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
|
+
}
|
|
136
187
|
async function closeDatabase(database) {
|
|
137
188
|
if (!database || typeof database !== "object")
|
|
138
189
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@farm.js/auth",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1-beta.1",
|
|
4
4
|
"description": "Farm-native authentication with email/password, server helpers, and React hooks",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"access": "public"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"better-auth": "1.
|
|
44
|
+
"better-auth": "1.7.7",
|
|
45
45
|
"pg": "8.20.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|