@ingram-tech/nk-auth 0.2.1 → 0.4.0
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/README.md +15 -4
- package/dist/client.d.ts +1 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +2 -0
- package/dist/client.js.map +1 -1
- package/dist/id.d.ts +32 -0
- package/dist/id.d.ts.map +1 -0
- package/dist/id.js +101 -0
- package/dist/id.js.map +1 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/options.d.ts +1 -5
- package/dist/options.d.ts.map +1 -1
- package/dist/options.js +4 -6
- package/dist/options.js.map +1 -1
- package/dist/paths.d.ts +16 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +16 -0
- package/dist/paths.js.map +1 -0
- package/dist/pool.d.ts +12 -11
- package/dist/pool.d.ts.map +1 -1
- package/dist/pool.js +16 -29
- package/dist/pool.js.map +1 -1
- package/package.json +11 -2
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ only what you need from focused subpaths.
|
|
|
22
22
|
> [`docs/better-auth-migration.md`](../../docs/better-auth-migration.md) — the
|
|
23
23
|
> RLS bridge, the migration runbook, and the gotchas.
|
|
24
24
|
>
|
|
25
|
-
> **Backend-JWT + org sites** (
|
|
25
|
+
> **Backend-JWT + org sites** (a backend API plus the org plugin): compose `createAuthPool`,
|
|
26
26
|
> `backendJwtOptions({ audience })`, `nkOrganizationDefaults`, and
|
|
27
27
|
> `lastActiveOrganizationHooks(pool)` in your `betterAuth()`; verify backend
|
|
28
28
|
> tokens with `verifyBackendJwt`. Keep app-specific bits (SSO restrictions,
|
|
@@ -73,6 +73,7 @@ per the prime directive. The presets carry the RLS-preserving bits.
|
|
|
73
73
|
import { passkey } from "@better-auth/passkey";
|
|
74
74
|
import { fromAddress, sendEmail } from "@ingram-tech/email";
|
|
75
75
|
import {
|
|
76
|
+
authBasePath,
|
|
76
77
|
authEnv,
|
|
77
78
|
bcryptPassword,
|
|
78
79
|
makeEmailSenders,
|
|
@@ -93,7 +94,13 @@ export const auth = betterAuth({
|
|
|
93
94
|
database: new Pool({ connectionString: env.databaseUrl }),
|
|
94
95
|
secret: env.secret,
|
|
95
96
|
baseURL: env.baseURL,
|
|
96
|
-
|
|
97
|
+
basePath: authBasePath, // mount at /auth, not the framework default /api/auth
|
|
98
|
+
advanced: { database: { generateId: uuidGenerateId } }, // UUIDv7 ids
|
|
99
|
+
// ^ stored as hyphenated UUIDv7 (uuid columns / Supabase RLS stay valid).
|
|
100
|
+
// To show those same ids as prefixed base58 on the wire/UI — `team_…`,
|
|
101
|
+
// matching the Ingram Cloud API's `agt_`/`smt_` ids — skin them with
|
|
102
|
+
// `toPrefixedId(uuid, "team")` / recover with `fromPrefixedId`. `base58Id`
|
|
103
|
+
// mints a fresh one directly for text-id sites. All from `@ingram-tech/nk-auth`.
|
|
97
104
|
emailAndPassword: {
|
|
98
105
|
enabled: true,
|
|
99
106
|
password: bcryptPassword, // verifies migrated Supabase bcrypt hashes
|
|
@@ -114,7 +121,9 @@ export const auth = betterAuth({
|
|
|
114
121
|
```
|
|
115
122
|
|
|
116
123
|
```ts
|
|
117
|
-
// app/
|
|
124
|
+
// app/auth/[...all]/route.ts — a standard Next.js route handler.
|
|
125
|
+
// Lives at /auth (set via `basePath: authBasePath`), NOT /api/auth: auth is a
|
|
126
|
+
// user-facing surface (sign-in, OAuth callbacks), not an internal machine API.
|
|
118
127
|
import { auth } from "@/lib/auth";
|
|
119
128
|
export const { GET, POST } = auth.handler;
|
|
120
129
|
```
|
|
@@ -153,6 +162,7 @@ preserved here too):
|
|
|
153
162
|
```tsx
|
|
154
163
|
"use client";
|
|
155
164
|
import {
|
|
165
|
+
authBasePath,
|
|
156
166
|
createAuthClient,
|
|
157
167
|
jwtClient,
|
|
158
168
|
passkeyClient,
|
|
@@ -160,6 +170,7 @@ import {
|
|
|
160
170
|
|
|
161
171
|
export const authClient = createAuthClient({
|
|
162
172
|
baseURL: process.env.NEXT_PUBLIC_SITE_URL ?? "",
|
|
173
|
+
basePath: authBasePath, // matches the server: /auth
|
|
163
174
|
plugins: [jwtClient(), passkeyClient()],
|
|
164
175
|
});
|
|
165
176
|
// authClient.signIn.email(...), signIn.social(...), useSession(), passkey.*
|
|
@@ -169,7 +180,7 @@ export const authClient = createAuthClient({
|
|
|
169
180
|
|
|
170
181
|
`auth.uid()` reads the `sub` claim of the JWT PostgREST receives. The `jwt`
|
|
171
182
|
plugin (configured here) mints an asymmetric token with `sub` = the user's UUID
|
|
172
|
-
and `role: "authenticated"`, exposed at `/
|
|
183
|
+
and `role: "authenticated"`, exposed at `/auth/jwks`. Register that JWKS URL
|
|
173
184
|
as a Supabase **third-party auth** issuer, and every existing policy works
|
|
174
185
|
unchanged. Full rationale and the HS256 fallback:
|
|
175
186
|
[`docs/better-auth-migration.md`](../../docs/better-auth-migration.md).
|
package/dist/client.d.ts
CHANGED
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/client.js
CHANGED
|
@@ -20,4 +20,6 @@
|
|
|
20
20
|
export { passkeyClient } from "@better-auth/passkey/client";
|
|
21
21
|
export { jwtClient } from "better-auth/client/plugins";
|
|
22
22
|
export { createAuthClient } from "better-auth/react";
|
|
23
|
+
// Re-exported here too so the client can set `basePath` without a server import.
|
|
24
|
+
export { authBasePath } from "./paths";
|
|
23
25
|
//# sourceMappingURL=client.js.map
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,iFAAiF;AACjF,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/id.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Ingram id codec — a UUIDv7 and its base58 skin. Dependency-light on
|
|
3
|
+
* purpose (only `node:crypto`), so a site can import it without pulling the
|
|
4
|
+
* bcrypt / passkey machinery in `./options`: `@ingram-tech/nk-auth/id`.
|
|
5
|
+
*
|
|
6
|
+
* The Python twin lives in cloud.ingram.tech's `v1/core.py` (`new_id`); the
|
|
7
|
+
* byte → string vectors in `id.test.ts` and that repo's `tests/test_ids.py` are
|
|
8
|
+
* kept identical, so a Better-Auth id (stored as a hyphenated UUIDv7 by
|
|
9
|
+
* {@link uuidGenerateId}) and an `agt_`/`smt_` id from the API are the same
|
|
10
|
+
* encoding of the same 16 bytes.
|
|
11
|
+
*
|
|
12
|
+
* The split is deliberate: keep storing the hyphenated UUIDv7 at rest (so
|
|
13
|
+
* Supabase `auth.uid()::uuid` / uuid columns keep working) and use
|
|
14
|
+
* {@link toPrefixedId} to skin it as a prefixed base58 id for the wire / display,
|
|
15
|
+
* {@link fromPrefixedId} to recover it. {@link base58Id} mints a fresh one
|
|
16
|
+
* directly, for text-id sites that want API-style ids natively.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* `advanced.database.generateId` for Better Auth — mints a **UUIDv7** (RFC 9562):
|
|
20
|
+
* a 48-bit Unix-ms timestamp prefix + random tail, version `7`, variant `10`.
|
|
21
|
+
* Keeps ids UUID-shaped (Supabase `auth.uid()::uuid`) while staying time-ordered
|
|
22
|
+
* for index locality. Node/Bun's `randomUUID` is v4-only, so we lay the bytes out
|
|
23
|
+
* by hand.
|
|
24
|
+
*/
|
|
25
|
+
export declare const uuidGenerateId: () => string;
|
|
26
|
+
/** Skin a stored hyphenated UUIDv7 as a prefixed base58 id, e.g. `team_…`. */
|
|
27
|
+
export declare function toPrefixedId(uuid: string, prefix: string): string;
|
|
28
|
+
/** Inverse of {@link toPrefixedId}: recover the hyphenated UUIDv7. */
|
|
29
|
+
export declare function fromPrefixedId(id: string): string;
|
|
30
|
+
/** Mint a fresh prefixed base58 id (UUIDv7 core), for text-id sites / API parity. */
|
|
31
|
+
export declare function base58Id(prefix: string): string;
|
|
32
|
+
//# sourceMappingURL=id.d.ts.map
|
package/dist/id.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"id.d.ts","sourceRoot":"","sources":["../src/id.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;GAgBG;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,QAAO,MAYjC,CAAC;AAqDF,8EAA8E;AAC9E,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAEjE;AAED,sEAAsE;AACtE,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAGjD;AAED,qFAAqF;AACrF,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAE/C"}
|
package/dist/id.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
/**
|
|
3
|
+
* The Ingram id codec — a UUIDv7 and its base58 skin. Dependency-light on
|
|
4
|
+
* purpose (only `node:crypto`), so a site can import it without pulling the
|
|
5
|
+
* bcrypt / passkey machinery in `./options`: `@ingram-tech/nk-auth/id`.
|
|
6
|
+
*
|
|
7
|
+
* The Python twin lives in cloud.ingram.tech's `v1/core.py` (`new_id`); the
|
|
8
|
+
* byte → string vectors in `id.test.ts` and that repo's `tests/test_ids.py` are
|
|
9
|
+
* kept identical, so a Better-Auth id (stored as a hyphenated UUIDv7 by
|
|
10
|
+
* {@link uuidGenerateId}) and an `agt_`/`smt_` id from the API are the same
|
|
11
|
+
* encoding of the same 16 bytes.
|
|
12
|
+
*
|
|
13
|
+
* The split is deliberate: keep storing the hyphenated UUIDv7 at rest (so
|
|
14
|
+
* Supabase `auth.uid()::uuid` / uuid columns keep working) and use
|
|
15
|
+
* {@link toPrefixedId} to skin it as a prefixed base58 id for the wire / display,
|
|
16
|
+
* {@link fromPrefixedId} to recover it. {@link base58Id} mints a fresh one
|
|
17
|
+
* directly, for text-id sites that want API-style ids natively.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* `advanced.database.generateId` for Better Auth — mints a **UUIDv7** (RFC 9562):
|
|
21
|
+
* a 48-bit Unix-ms timestamp prefix + random tail, version `7`, variant `10`.
|
|
22
|
+
* Keeps ids UUID-shaped (Supabase `auth.uid()::uuid`) while staying time-ordered
|
|
23
|
+
* for index locality. Node/Bun's `randomUUID` is v4-only, so we lay the bytes out
|
|
24
|
+
* by hand.
|
|
25
|
+
*/
|
|
26
|
+
export const uuidGenerateId = () => {
|
|
27
|
+
const bytes = randomBytes(16);
|
|
28
|
+
const ts = Date.now();
|
|
29
|
+
bytes[0] = Math.floor(ts / 2 ** 40) & 0xff;
|
|
30
|
+
bytes[1] = Math.floor(ts / 2 ** 32) & 0xff;
|
|
31
|
+
bytes[2] = Math.floor(ts / 2 ** 24) & 0xff;
|
|
32
|
+
bytes[3] = Math.floor(ts / 2 ** 16) & 0xff;
|
|
33
|
+
bytes[4] = Math.floor(ts / 2 ** 8) & 0xff;
|
|
34
|
+
bytes[5] = ts & 0xff;
|
|
35
|
+
bytes[6] = ((bytes[6] ?? 0) & 0x0f) | 0x70; // version 7
|
|
36
|
+
bytes[8] = ((bytes[8] ?? 0) & 0x3f) | 0x80; // variant 10
|
|
37
|
+
return bytesToUuid(bytes);
|
|
38
|
+
};
|
|
39
|
+
const B58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
40
|
+
// ceil(128 / log2(58)): a 16-byte value never needs more than 22 digits. We
|
|
41
|
+
// left-pad to it so every body is uniform width and sorts lexically ==
|
|
42
|
+
// chronologically (UUIDv7's ms-timestamp prefix lives in the high bytes).
|
|
43
|
+
const WIDTH = 22;
|
|
44
|
+
/** Big-endian base58 (Bitcoin alphabet) of 16 bytes, left-padded to `WIDTH`. */
|
|
45
|
+
function encode58(bytes) {
|
|
46
|
+
let n = 0n;
|
|
47
|
+
for (const b of bytes)
|
|
48
|
+
n = (n << 8n) | BigInt(b);
|
|
49
|
+
let out = "";
|
|
50
|
+
while (n > 0n) {
|
|
51
|
+
out = B58.charAt(Number(n % 58n)) + out;
|
|
52
|
+
n /= 58n;
|
|
53
|
+
}
|
|
54
|
+
return out.padStart(WIDTH, B58.charAt(0));
|
|
55
|
+
}
|
|
56
|
+
/** Inverse of {@link encode58}: a base58 body back to 16 bytes. */
|
|
57
|
+
function decode58(body) {
|
|
58
|
+
let n = 0n;
|
|
59
|
+
for (const ch of body) {
|
|
60
|
+
const v = B58.indexOf(ch);
|
|
61
|
+
if (v < 0)
|
|
62
|
+
throw new Error(`invalid base58 char: ${ch}`);
|
|
63
|
+
n = n * 58n + BigInt(v);
|
|
64
|
+
}
|
|
65
|
+
const bytes = new Uint8Array(16);
|
|
66
|
+
for (let i = 15; i >= 0; i--) {
|
|
67
|
+
bytes[i] = Number(n & 0xffn);
|
|
68
|
+
n >>= 8n;
|
|
69
|
+
}
|
|
70
|
+
return bytes;
|
|
71
|
+
}
|
|
72
|
+
/** A hyphenated UUID string → its 16 raw bytes. */
|
|
73
|
+
function uuidToBytes(uuid) {
|
|
74
|
+
const hex = uuid.replace(/-/g, "");
|
|
75
|
+
if (!/^[0-9a-fA-F]{32}$/.test(hex))
|
|
76
|
+
throw new Error(`not a uuid: ${uuid}`);
|
|
77
|
+
const bytes = new Uint8Array(16);
|
|
78
|
+
for (let i = 0; i < 16; i++) {
|
|
79
|
+
bytes[i] = Number.parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
|
80
|
+
}
|
|
81
|
+
return bytes;
|
|
82
|
+
}
|
|
83
|
+
/** 16 raw bytes → a canonical hyphenated UUID string. */
|
|
84
|
+
function bytesToUuid(bytes) {
|
|
85
|
+
const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
86
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
87
|
+
}
|
|
88
|
+
/** Skin a stored hyphenated UUIDv7 as a prefixed base58 id, e.g. `team_…`. */
|
|
89
|
+
export function toPrefixedId(uuid, prefix) {
|
|
90
|
+
return `${prefix}_${encode58(uuidToBytes(uuid))}`;
|
|
91
|
+
}
|
|
92
|
+
/** Inverse of {@link toPrefixedId}: recover the hyphenated UUIDv7. */
|
|
93
|
+
export function fromPrefixedId(id) {
|
|
94
|
+
const body = id.slice(id.indexOf("_") + 1);
|
|
95
|
+
return bytesToUuid(decode58(body));
|
|
96
|
+
}
|
|
97
|
+
/** Mint a fresh prefixed base58 id (UUIDv7 core), for text-id sites / API parity. */
|
|
98
|
+
export function base58Id(prefix) {
|
|
99
|
+
return toPrefixedId(uuidGenerateId(), prefix);
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=id.js.map
|
package/dist/id.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"id.js","sourceRoot":"","sources":["../src/id.ts"],"names":[],"mappings":"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"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export { type BackendJwtConfig, backendJwtOptions, rlsJwtOptions, verifyBackendJwt, } from "./jwt";
|
|
2
|
+
export { base58Id, fromPrefixedId, toPrefixedId, uuidGenerateId } from "./id";
|
|
2
3
|
export { type AuthEnv, authEnv, isConfigured } from "./keys";
|
|
3
|
-
export { bcryptPassword, makeEmailSenders, makePasskeyOptions, type PasskeyConfig, type SendEmail,
|
|
4
|
+
export { bcryptPassword, makeEmailSenders, makePasskeyOptions, type PasskeyConfig, type SendEmail, } from "./options";
|
|
4
5
|
export { lastActiveOrganizationHooks, lastActiveOrganizationUserField, nkOrganizationDefaults, } from "./organization";
|
|
6
|
+
export { authBasePath } from "./paths";
|
|
5
7
|
export { createAuthPool } from "./pool";
|
|
6
|
-
export { createServerSupabase, type ServerSupabaseConfig
|
|
8
|
+
export { createServerSupabase, type ServerSupabaseConfig } from "./supabase";
|
|
7
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EACN,KAAK,gBAAgB,EACrB,iBAAiB,EACjB,aAAa,EACb,gBAAgB,GAChB,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,KAAK,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAC7D,OAAO,EACN,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,KAAK,aAAa,EAClB,KAAK,SAAS,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EACN,KAAK,gBAAgB,EACrB,iBAAiB,EACjB,aAAa,EACb,gBAAgB,GAChB,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAC9E,OAAO,EAAE,KAAK,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAC7D,OAAO,EACN,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,KAAK,aAAa,EAClB,KAAK,SAAS,GACd,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,2BAA2B,EAC3B,+BAA+B,EAC/B,sBAAsB,GACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,KAAK,oBAAoB,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
// React. Focused subpaths (./jwt, ./organization, ./pool) let a site import
|
|
4
4
|
// only what it needs (e.g. avoid bcrypt/supabase when it uses neither).
|
|
5
5
|
export { backendJwtOptions, rlsJwtOptions, verifyBackendJwt, } from "./jwt";
|
|
6
|
+
export { base58Id, fromPrefixedId, toPrefixedId, uuidGenerateId } from "./id";
|
|
6
7
|
export { authEnv, isConfigured } from "./keys";
|
|
7
|
-
export { bcryptPassword, makeEmailSenders, makePasskeyOptions,
|
|
8
|
+
export { bcryptPassword, makeEmailSenders, makePasskeyOptions, } from "./options";
|
|
8
9
|
export { lastActiveOrganizationHooks, lastActiveOrganizationUserField, nkOrganizationDefaults, } from "./organization";
|
|
10
|
+
export { authBasePath } from "./paths";
|
|
9
11
|
export { createAuthPool } from "./pool";
|
|
10
|
-
export { createServerSupabase
|
|
12
|
+
export { createServerSupabase } from "./supabase";
|
|
11
13
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,+EAA+E;AAC/E,4EAA4E;AAC5E,wEAAwE;AAExE,OAAO,EAEN,iBAAiB,EACjB,aAAa,EACb,gBAAgB,GAChB,MAAM,OAAO,CAAC;AACf,OAAO,EAAgB,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAC7D,OAAO,EACN,cAAc,EACd,gBAAgB,EAChB,kBAAkB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,+EAA+E;AAC/E,4EAA4E;AAC5E,wEAAwE;AAExE,OAAO,EAEN,iBAAiB,EACjB,aAAa,EACb,gBAAgB,GAChB,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAC9E,OAAO,EAAgB,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAC7D,OAAO,EACN,cAAc,EACd,gBAAgB,EAChB,kBAAkB,GAGlB,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,2BAA2B,EAC3B,+BAA+B,EAC/B,sBAAsB,GACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAA6B,MAAM,YAAY,CAAC"}
|
package/dist/options.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { PasskeyOptions } from "@better-auth/passkey";
|
|
2
|
+
export { uuidGenerateId } from "./id";
|
|
2
3
|
/**
|
|
3
4
|
* Portable Better Auth building blocks for Ingram sites.
|
|
4
5
|
*
|
|
@@ -7,9 +8,6 @@ import type { PasskeyOptions } from "@better-auth/passkey";
|
|
|
7
8
|
* call site (where `declaration` is off) and respects the prime directive — the
|
|
8
9
|
* site stays plain Better Auth, we just ship the shared config. JWT + org
|
|
9
10
|
* presets live in `./jwt` and `./organization`. See docs/better-auth-migration.md.
|
|
10
|
-
*
|
|
11
|
-
* `uuidGenerateId` keeps new-user ids UUID-shaped (needed for Supabase
|
|
12
|
-
* `auth.uid()::uuid` on RLS sites).
|
|
13
11
|
*/
|
|
14
12
|
/**
|
|
15
13
|
* `emailAndPassword.password` config. Verifies with bcrypt so passwords
|
|
@@ -22,8 +20,6 @@ export declare const bcryptPassword: {
|
|
|
22
20
|
password: string;
|
|
23
21
|
}) => Promise<boolean>;
|
|
24
22
|
};
|
|
25
|
-
/** `advanced.database.generateId` — keeps new-user ids UUID-shaped. */
|
|
26
|
-
export declare const uuidGenerateId: () => string;
|
|
27
23
|
export interface PasskeyConfig {
|
|
28
24
|
/** Relying-party id: the registrable domain, e.g. "example.com". */
|
|
29
25
|
rpId: string;
|
package/dist/options.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAM3D,OAAO,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAEtC;;;;;;;;GAQG;AAEH;;;GAGG;AACH,eAAO,MAAM,cAAc;qBACT,MAAM,KAAG,OAAO,CAAC,MAAM,CAAC;kCAItC;QACF,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;KACjB,KAAG,OAAO,CAAC,OAAO,CAAC;CACpB,CAAC;AAEF,MAAM,WAAW,aAAa;IAC7B,oEAAoE;IACpE,IAAI,EAAE,MAAM,CAAC;IACb,kCAAkC;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,sDAAsD;IACtD,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAC1B;AAED,iFAAiF;AACjF,eAAO,MAAM,kBAAkB,GAAI,KAAK,aAAa,KAAG,cAItD,CAAC;AAEH,iFAAiF;AACjF,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,EAAE;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;CACZ,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAEvB;;;GAGG;AACH,eAAO,MAAM,gBAAgB,GAAI,MAAM,SAAS;wCAI5C;QACF,IAAI,EAAE;YAAE,KAAK,EAAE,MAAM,CAAA;SAAE,CAAC;QACxB,GAAG,EAAE,MAAM,CAAC;KACZ,KAAG,OAAO,CAAC,IAAI,CAAC;4CAMd;QACF,IAAI,EAAE;YAAE,KAAK,EAAE,MAAM,CAAA;SAAE,CAAC;QACxB,GAAG,EAAE,MAAM,CAAC;KACZ,KAAG,OAAO,CAAC,IAAI,CAAC;CAGhB,CAAC"}
|
package/dist/options.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
1
|
import bcrypt from "bcrypt";
|
|
2
|
+
// `uuidGenerateId` (the `advanced.database.generateId` UUIDv7 generator) and the
|
|
3
|
+
// base58 skin now live in the dependency-light `./id` module; re-exported here so
|
|
4
|
+
// existing `from "@ingram-tech/nk-auth"` imports keep resolving.
|
|
5
|
+
export { uuidGenerateId } from "./id";
|
|
3
6
|
/**
|
|
4
7
|
* Portable Better Auth building blocks for Ingram sites.
|
|
5
8
|
*
|
|
@@ -8,9 +11,6 @@ import bcrypt from "bcrypt";
|
|
|
8
11
|
* call site (where `declaration` is off) and respects the prime directive — the
|
|
9
12
|
* site stays plain Better Auth, we just ship the shared config. JWT + org
|
|
10
13
|
* presets live in `./jwt` and `./organization`. See docs/better-auth-migration.md.
|
|
11
|
-
*
|
|
12
|
-
* `uuidGenerateId` keeps new-user ids UUID-shaped (needed for Supabase
|
|
13
|
-
* `auth.uid()::uuid` on RLS sites).
|
|
14
14
|
*/
|
|
15
15
|
/**
|
|
16
16
|
* `emailAndPassword.password` config. Verifies with bcrypt so passwords
|
|
@@ -20,8 +20,6 @@ export const bcryptPassword = {
|
|
|
20
20
|
hash: (password) => bcrypt.hash(password, 10),
|
|
21
21
|
verify: ({ hash, password, }) => bcrypt.compare(password, hash),
|
|
22
22
|
};
|
|
23
|
-
/** `advanced.database.generateId` — keeps new-user ids UUID-shaped. */
|
|
24
|
-
export const uuidGenerateId = () => randomUUID();
|
|
25
23
|
/** Build `passkey` plugin options. Use as `passkey(makePasskeyOptions(cfg))`. */
|
|
26
24
|
export const makePasskeyOptions = (cfg) => ({
|
|
27
25
|
rpID: cfg.rpId,
|
package/dist/options.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,iFAAiF;AACjF,kFAAkF;AAClF,iEAAiE;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAEtC;;;;;;;;GAQG;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC7B,IAAI,EAAE,CAAC,QAAgB,EAAmB,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC;IACtE,MAAM,EAAE,CAAC,EACR,IAAI,EACJ,QAAQ,GAIR,EAAoB,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC;CACtD,CAAC;AAWF,iFAAiF;AACjF,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,GAAkB,EAAkB,EAAE,CAAC,CAAC;IAC1E,IAAI,EAAE,GAAG,CAAC,IAAI;IACd,MAAM,EAAE,GAAG,CAAC,MAAM;IAClB,MAAM,EAAE,GAAG,CAAC,MAAM;CAClB,CAAC,CAAC;AASH;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,IAAe,EAAE,EAAE,CAAC,CAAC;IACrD,iBAAiB,EAAE,KAAK,EAAE,EACzB,IAAI,EACJ,GAAG,GAIH,EAAiB,EAAE;QACnB,MAAM,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,qBAAqB,EAAE,GAAG,EAAE,CAAC,CAAC;IACrE,CAAC;IACD,qBAAqB,EAAE,KAAK,EAAE,EAC7B,IAAI,EACJ,GAAG,GAIH,EAAiB,EAAE;QACnB,MAAM,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,mBAAmB,EAAE,GAAG,EAAE,CAAC,CAAC;IACnE,CAAC;CACD,CAAC,CAAC"}
|
package/dist/paths.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where Better Auth mounts in an Ingram site: **`/auth`**, not the framework
|
|
3
|
+
* default `/api/auth`. Auth is a first-class user-facing surface — sign-in,
|
|
4
|
+
* OAuth callbacks, the JWKS — not an internal machine API, so it lives at the
|
|
5
|
+
* site root alongside the other pages.
|
|
6
|
+
*
|
|
7
|
+
* Use it on both ends so server and client agree:
|
|
8
|
+
*
|
|
9
|
+
* betterAuth({ basePath: authBasePath, ... })
|
|
10
|
+
* createAuthClient({ baseURL, basePath: authBasePath, ... })
|
|
11
|
+
*
|
|
12
|
+
* and mount the catch-all at `app/auth/[...all]/route.ts`. OAuth redirect URIs
|
|
13
|
+
* then become `<site>/auth/callback/<provider>` and the JWKS `<site>/auth/jwks`.
|
|
14
|
+
*/
|
|
15
|
+
export declare const authBasePath = "/auth";
|
|
16
|
+
//# sourceMappingURL=paths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,YAAY,UAAU,CAAC"}
|
package/dist/paths.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where Better Auth mounts in an Ingram site: **`/auth`**, not the framework
|
|
3
|
+
* default `/api/auth`. Auth is a first-class user-facing surface — sign-in,
|
|
4
|
+
* OAuth callbacks, the JWKS — not an internal machine API, so it lives at the
|
|
5
|
+
* site root alongside the other pages.
|
|
6
|
+
*
|
|
7
|
+
* Use it on both ends so server and client agree:
|
|
8
|
+
*
|
|
9
|
+
* betterAuth({ basePath: authBasePath, ... })
|
|
10
|
+
* createAuthClient({ baseURL, basePath: authBasePath, ... })
|
|
11
|
+
*
|
|
12
|
+
* and mount the catch-all at `app/auth/[...all]/route.ts`. OAuth redirect URIs
|
|
13
|
+
* then become `<site>/auth/callback/<provider>` and the JWKS `<site>/auth/jwks`.
|
|
14
|
+
*/
|
|
15
|
+
export const authBasePath = "/auth";
|
|
16
|
+
//# sourceMappingURL=paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,OAAO,CAAC"}
|
package/dist/pool.d.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import { Pool } from "pg";
|
|
1
|
+
import type { Pool } from "pg";
|
|
2
2
|
/**
|
|
3
|
-
* A `pg` Pool for Better Auth's direct database connection
|
|
4
|
-
* for each kind of host:
|
|
3
|
+
* A `pg` Pool for Better Auth's direct database connection.
|
|
5
4
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
5
|
+
* @deprecated Thin alias for `createPool` from `@ingram-tech/nk-db` — the one
|
|
6
|
+
* place pool construction and TLS handling live. Kept so existing call sites
|
|
7
|
+
* (`lib/db.ts` calling `createAuthPool({ connectionString, caCert })`) keep
|
|
8
|
+
* working, and so Better Auth shares the **exact same pool implementation** as
|
|
9
|
+
* app queries — the "one pool per process" rule. Prefer importing `createPool`
|
|
10
|
+
* directly in new code.
|
|
11
|
+
*
|
|
12
|
+
* TLS handling (CA-verified when `caCert` is set; plain-TLS for other managed
|
|
13
|
+
* hosts; no TLS for localhost), and the local `max: 1` cap (for the PGlite
|
|
14
|
+
* socket), all live in `createPool`.
|
|
14
15
|
*/
|
|
15
16
|
export declare const createAuthPool: (config: {
|
|
16
17
|
connectionString: string;
|
package/dist/pool.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../src/pool.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../src/pool.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAE/B;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,cAAc,GAAI,QAAQ;IACtC,gBAAgB,EAAE,MAAM,CAAC;IACzB,sEAAsE;IACtE,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB,KAAG,IAID,CAAC"}
|
package/dist/pool.js
CHANGED
|
@@ -1,33 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
const isLocal = (connectionString) => connectionString.includes("127.0.0.1") || connectionString.includes("localhost");
|
|
1
|
+
import { createPool } from "@ingram-tech/nk-db";
|
|
3
2
|
/**
|
|
4
|
-
* A `pg` Pool for Better Auth's direct database connection
|
|
5
|
-
* for each kind of host:
|
|
3
|
+
* A `pg` Pool for Better Auth's direct database connection.
|
|
6
4
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
5
|
+
* @deprecated Thin alias for `createPool` from `@ingram-tech/nk-db` — the one
|
|
6
|
+
* place pool construction and TLS handling live. Kept so existing call sites
|
|
7
|
+
* (`lib/db.ts` calling `createAuthPool({ connectionString, caCert })`) keep
|
|
8
|
+
* working, and so Better Auth shares the **exact same pool implementation** as
|
|
9
|
+
* app queries — the "one pool per process" rule. Prefer importing `createPool`
|
|
10
|
+
* directly in new code.
|
|
11
|
+
*
|
|
12
|
+
* TLS handling (CA-verified when `caCert` is set; plain-TLS for other managed
|
|
13
|
+
* hosts; no TLS for localhost), and the local `max: 1` cap (for the PGlite
|
|
14
|
+
* socket), all live in `createPool`.
|
|
15
15
|
*/
|
|
16
|
-
export const createAuthPool = (config) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
};
|
|
16
|
+
export const createAuthPool = (config) => createPool({
|
|
17
|
+
connectionString: config.connectionString,
|
|
18
|
+
caCert: config.caCert,
|
|
19
|
+
});
|
|
33
20
|
//# 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,EAAE,
|
|
1
|
+
{"version":3,"file":"pool.js","sourceRoot":"","sources":["../src/pool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGhD;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,MAI9B,EAAQ,EAAE,CACV,UAAU,CAAC;IACV,gBAAgB,EAAE,MAAM,CAAC,gBAAgB;IACzC,MAAM,EAAE,MAAM,CAAC,MAAM;CACrB,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ingram-tech/nk-auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
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",
|
|
@@ -21,6 +21,10 @@
|
|
|
21
21
|
"types": "./dist/index.d.ts",
|
|
22
22
|
"import": "./dist/index.js"
|
|
23
23
|
},
|
|
24
|
+
"./id": {
|
|
25
|
+
"types": "./dist/id.d.ts",
|
|
26
|
+
"import": "./dist/id.js"
|
|
27
|
+
},
|
|
24
28
|
"./jwt": {
|
|
25
29
|
"types": "./dist/jwt.d.ts",
|
|
26
30
|
"import": "./dist/jwt.js"
|
|
@@ -33,6 +37,10 @@
|
|
|
33
37
|
"types": "./dist/pool.d.ts",
|
|
34
38
|
"import": "./dist/pool.js"
|
|
35
39
|
},
|
|
40
|
+
"./paths": {
|
|
41
|
+
"types": "./dist/paths.d.ts",
|
|
42
|
+
"import": "./dist/paths.js"
|
|
43
|
+
},
|
|
36
44
|
"./client": {
|
|
37
45
|
"types": "./dist/client.d.ts",
|
|
38
46
|
"import": "./dist/client.js"
|
|
@@ -45,6 +53,7 @@
|
|
|
45
53
|
"test": "vitest run"
|
|
46
54
|
},
|
|
47
55
|
"dependencies": {
|
|
56
|
+
"@ingram-tech/nk-db": "^0.2.0",
|
|
48
57
|
"bcrypt": "^5.1.1",
|
|
49
58
|
"jose": "^6.0.0",
|
|
50
59
|
"zod": "^4.0.0"
|
|
@@ -72,7 +81,7 @@
|
|
|
72
81
|
},
|
|
73
82
|
"devDependencies": {
|
|
74
83
|
"@better-auth/passkey": "^1.6.0",
|
|
75
|
-
"@ingram-tech/typescript-config": "
|
|
84
|
+
"@ingram-tech/typescript-config": "workspace:*",
|
|
76
85
|
"@supabase/supabase-js": "^2.45.0",
|
|
77
86
|
"@types/bcrypt": "^5.0.2",
|
|
78
87
|
"@types/node": "^20.0.0",
|