@ingram-tech/nk-auth 0.2.0 → 0.2.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/pool.d.ts CHANGED
@@ -1,9 +1,16 @@
1
1
  import { Pool } from "pg";
2
2
  /**
3
- * A `pg` Pool for Better Auth's direct database connection, with optional
4
- * SSL CA verification (equivalent to `sslmode=verify-full`). Keep `sslmode` out
5
- * of the connection string — `pg` discards the `ssl` object when the URL
6
- * carries SSL settings.
3
+ * A `pg` Pool for Better Auth's direct database connection, with the right TLS
4
+ * for each kind of host:
5
+ *
6
+ * - `caCert` set → verify the server cert + hostname against it
7
+ * (equivalent to `sslmode=verify-full`).
8
+ * - local (`127.0.0.1`/`localhost`) → no TLS.
9
+ * - otherwise (managed Postgres like Supabase) → TLS **without** chain
10
+ * verification. Supabase's cert chain isn't in Node's trust store, so plain
11
+ * verification fails with "self-signed certificate in certificate chain";
12
+ * the connection is still encrypted. `sslmode` is stripped from the URL
13
+ * because `pg` ignores the `ssl` object when the URL carries SSL settings.
7
14
  */
8
15
  export declare const createAuthPool: (config: {
9
16
  connectionString: string;
@@ -1 +1 @@
1
- {"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../src/pool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAE1B;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,QAAQ;IACtC,gBAAgB,EAAE,MAAM,CAAC;IACzB,sEAAsE;IACtE,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB,KAAG,IAMD,CAAC"}
1
+ {"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../src/pool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAK1B;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,cAAc,GAAI,QAAQ;IACtC,gBAAgB,EAAE,MAAM,CAAC;IACzB,sEAAsE;IACtE,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB,KAAG,IAgBH,CAAC"}
package/dist/pool.js CHANGED
@@ -1,14 +1,33 @@
1
1
  import { Pool } from "pg";
2
+ const isLocal = (connectionString) => connectionString.includes("127.0.0.1") || connectionString.includes("localhost");
2
3
  /**
3
- * A `pg` Pool for Better Auth's direct database connection, with optional
4
- * SSL CA verification (equivalent to `sslmode=verify-full`). Keep `sslmode` out
5
- * of the connection string — `pg` discards the `ssl` object when the URL
6
- * carries SSL settings.
4
+ * A `pg` Pool for Better Auth's direct database connection, with the right TLS
5
+ * for each kind of host:
6
+ *
7
+ * - `caCert` set → verify the server cert + hostname against it
8
+ * (equivalent to `sslmode=verify-full`).
9
+ * - local (`127.0.0.1`/`localhost`) → no TLS.
10
+ * - otherwise (managed Postgres like Supabase) → TLS **without** chain
11
+ * verification. Supabase's cert chain isn't in Node's trust store, so plain
12
+ * verification fails with "self-signed certificate in certificate chain";
13
+ * the connection is still encrypted. `sslmode` is stripped from the URL
14
+ * because `pg` ignores the `ssl` object when the URL carries SSL settings.
7
15
  */
8
- export const createAuthPool = (config) => new Pool({
9
- connectionString: config.connectionString,
10
- ssl: config.caCert
11
- ? { ca: config.caCert, rejectUnauthorized: true }
12
- : undefined,
13
- });
16
+ export const createAuthPool = (config) => {
17
+ if (config.caCert) {
18
+ return new Pool({
19
+ connectionString: config.connectionString,
20
+ ssl: { ca: config.caCert, rejectUnauthorized: true },
21
+ });
22
+ }
23
+ if (isLocal(config.connectionString)) {
24
+ return new Pool({ connectionString: config.connectionString });
25
+ }
26
+ const url = new URL(config.connectionString);
27
+ url.searchParams.delete("sslmode");
28
+ return new Pool({
29
+ connectionString: url.toString(),
30
+ ssl: { rejectUnauthorized: false },
31
+ });
32
+ };
14
33
  //# sourceMappingURL=pool.js.map
package/dist/pool.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"pool.js","sourceRoot":"","sources":["../src/pool.ts"],"names":[],"mappings":"AAAA,OAAO,EA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,IAAI,CAAC;QACf,gBAAgB,EAAE,GAAG,CAAC,QAAQ,EAAE;QAChC,GAAG,EAAE,EAAE,kBAAkB,EAAE,KAAK,EAAE;KAClC,CAAC,CAAC;AACJ,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ingram-tech/nk-auth",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "The Ingram Better Auth foundation: composable presets (org, dual-shape JWT, Supabase RLS bridge, active-org hooks, pg pool) for Next.js sites.",
5
5
  "license": "MIT",
6
6
  "type": "module",