@farm.js/auth 0.1.39 → 0.1.40
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.map +1 -1
- package/dist/internal.js +2 -2
- package/dist/runtime.d.ts +7 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +26 -0
- package/package.json +1 -1
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;AAUzD,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, compileFarmAuthMigration as runCompileMigration, } from "./runtime.js";
|
|
1
|
+
import { configureFarmAuth, disposeFarmAuth as runDispose, getFarmAuthRuntime, migrateFarmAuth as runMigration, withFarmAuthClientAddress, compileFarmAuthMigration as runCompileMigration, } from "./runtime.js";
|
|
2
2
|
export function createFarmAuthIntegration(config, options) {
|
|
3
3
|
configureFarmAuth(config, options);
|
|
4
4
|
return {
|
|
@@ -12,7 +12,7 @@ export function createFarmAuthIntegration(config, options) {
|
|
|
12
12
|
methods: ["GET", "POST"],
|
|
13
13
|
async handler(request) {
|
|
14
14
|
const runtime = await getFarmAuthRuntime();
|
|
15
|
-
return runtime.handler(request);
|
|
15
|
+
return runtime.handler(withFarmAuthClientAddress(request));
|
|
16
16
|
},
|
|
17
17
|
},
|
|
18
18
|
],
|
package/dist/runtime.d.ts
CHANGED
|
@@ -13,6 +13,13 @@ interface BetterAuthRuntime {
|
|
|
13
13
|
}
|
|
14
14
|
export declare function configureFarmAuth(config: ResolvedFarmAuthConfig, options: FarmAuthRuntimeOptions): void;
|
|
15
15
|
export declare function getFarmAuthRuntime(): Promise<BetterAuthRuntime>;
|
|
16
|
+
/**
|
|
17
|
+
* The request Better Auth's handler sees, carrying the client address Farm
|
|
18
|
+
* resolved. Better Auth keys its sign-in rate limit on that address; left to
|
|
19
|
+
* its default it reads a client-supplied single-value x-forwarded-for, so a
|
|
20
|
+
* rotating header bypassed the limit and requests without one shared a bucket.
|
|
21
|
+
*/
|
|
22
|
+
export declare function withFarmAuthClientAddress(request: Request): Request;
|
|
16
23
|
export declare function getFarmAuthRequest(request?: Request): Request;
|
|
17
24
|
/**
|
|
18
25
|
* Close the connection opened for the runtime and drop the cached instance.
|
package/dist/runtime.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAazD,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;IAC7C,GAAG,EAAE;QACH,UAAU,CAAC,KAAK,EAAE;YAAE,OAAO,EAAE,OAAO,CAAA;SAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;KAC3D,CAAC;CACH;AAqBD,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,sBAAsB,EAC9B,OAAO,EAAE,sBAAsB,GAC9B,IAAI,CAeN;AAED,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,iBAAiB,CAAC,CA6BrE;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CASnE;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;AAsID;;;;;;;;;;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
|
@@ -5,6 +5,12 @@ import path from "node:path";
|
|
|
5
5
|
const FARM_AUTH_STATE_KEY = Symbol.for("@farm.js/auth/runtime");
|
|
6
6
|
const CURRENT_REQUEST_RESOLVER_KEY = Symbol.for("farm.currentRequestResolver");
|
|
7
7
|
const loadNodeModule = createRequire(import.meta.url);
|
|
8
|
+
/**
|
|
9
|
+
* Where Better Auth reads the caller's address from. Farm Auth sets it from the
|
|
10
|
+
* address Farm resolved for the request (the server's peer address, or the
|
|
11
|
+
* forwarded one under `server.trustProxy`) and drops any copy the client sent.
|
|
12
|
+
*/
|
|
13
|
+
const CLIENT_ADDRESS_HEADER = "x-farm-auth-client-address";
|
|
8
14
|
function getState() {
|
|
9
15
|
const runtime = globalThis;
|
|
10
16
|
runtime[FARM_AUTH_STATE_KEY] ||= {};
|
|
@@ -54,6 +60,23 @@ export async function getFarmAuthRuntime() {
|
|
|
54
60
|
}
|
|
55
61
|
return state.runtime;
|
|
56
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* The request Better Auth's handler sees, carrying the client address Farm
|
|
65
|
+
* resolved. Better Auth keys its sign-in rate limit on that address; left to
|
|
66
|
+
* its default it reads a client-supplied single-value x-forwarded-for, so a
|
|
67
|
+
* rotating header bypassed the limit and requests without one shared a bucket.
|
|
68
|
+
*/
|
|
69
|
+
export function withFarmAuthClientAddress(request) {
|
|
70
|
+
const address = request.socket
|
|
71
|
+
?.remoteAddress;
|
|
72
|
+
if (!address && !request.headers.has(CLIENT_ADDRESS_HEADER))
|
|
73
|
+
return request;
|
|
74
|
+
const headers = new Headers(request.headers);
|
|
75
|
+
headers.delete(CLIENT_ADDRESS_HEADER);
|
|
76
|
+
if (address)
|
|
77
|
+
headers.set(CLIENT_ADDRESS_HEADER, address);
|
|
78
|
+
return new Request(request, { headers });
|
|
79
|
+
}
|
|
57
80
|
export function getFarmAuthRequest(request) {
|
|
58
81
|
if (request)
|
|
59
82
|
return request;
|
|
@@ -143,6 +166,9 @@ async function createBetterAuthOptions(config, options, runtimeOptions = {}) {
|
|
|
143
166
|
expiresIn: config.session.expiresIn,
|
|
144
167
|
updateAge: config.session.updateAge,
|
|
145
168
|
},
|
|
169
|
+
advanced: {
|
|
170
|
+
ipAddress: { ipAddressHeaders: [CLIENT_ADDRESS_HEADER] },
|
|
171
|
+
},
|
|
146
172
|
};
|
|
147
173
|
}
|
|
148
174
|
/** Random secrets used when a project directory cannot hold one, kept for the process. */
|