@sanoma-ai/connector-better-auth 0.2.4 → 0.2.6
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 +5 -5
- package/dist/db/staff.d.ts +695 -0
- package/dist/db/staff.js +4 -0
- package/dist/db/staff.js.map +1 -0
- package/dist/db/tables.d.ts +702 -0
- package/dist/db/tables.js +69 -0
- package/dist/db/tables.js.map +1 -0
- package/dist/db/visitors.d.ts +695 -0
- package/dist/db/visitors.js +4 -0
- package/dist/db/visitors.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/instance.d.ts +137 -78
- package/dist/instance.js +133 -59
- package/dist/instance.js.map +1 -1
- package/dist/login.d.ts +5 -5
- package/dist/login.js +19 -21
- package/dist/login.js.map +1 -1
- package/dist/staff.d.ts +3 -2
- package/dist/staff.js +56 -32
- package/dist/staff.js.map +1 -1
- package/drizzle/staff/0000_closed_toro.sql +64 -0
- package/drizzle/staff/meta/0000_snapshot.json +431 -0
- package/drizzle/staff/meta/_journal.json +13 -0
- package/drizzle/visitors/0000_natural_dexter_bennett.sql +64 -0
- package/drizzle/visitors/meta/0000_snapshot.json +431 -0
- package/drizzle/visitors/meta/_journal.json +13 -0
- package/package.json +11 -8
package/dist/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { withSetup } from "@sanoma-ai/workflows";
|
|
2
2
|
import { betterAuthOps } from "./connector.js";
|
|
3
|
+
import { prepareBetterAuth } from "./instance.js";
|
|
3
4
|
import { betterAuthLogin } from "./login.js";
|
|
5
|
+
export { prepareBetterAuth, prepareBetterAuthStaff } from "./instance.js";
|
|
4
6
|
export { betterAuthLogin } from "./login.js";
|
|
5
7
|
export { betterAuthStaffLogin } from "./staff.js";
|
|
6
8
|
/**
|
|
@@ -10,5 +12,5 @@ export { betterAuthStaffLogin } from "./staff.js";
|
|
|
10
12
|
* signed with the key the app derives for it. The staff login is `betterAuthStaffLogin`, which the
|
|
11
13
|
* `sanoma` launcher runs on a host.
|
|
12
14
|
*/
|
|
13
|
-
export const betterAuth = withSetup(betterAuthOps, { login: betterAuthLogin });
|
|
15
|
+
export const betterAuth = withSetup(betterAuthOps, { prepare: prepareBetterAuth, login: betterAuthLogin });
|
|
14
16
|
//# 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,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAElD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,SAAS,CAAC,aAAa,EAAE,EAAE,KAAK,EAAE,eAAe,EAAE,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAElD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,SAAS,CAAC,aAAa,EAAE,EAAE,OAAO,EAAE,iBAAiB,EAAE,KAAK,EAAE,eAAe,EAAE,CAAC,CAAC"}
|
package/dist/instance.d.ts
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
import { type BetterAuthOptions } from "better-auth";
|
|
2
|
-
import {
|
|
3
|
-
import { Pool } from "pg";
|
|
2
|
+
import type { Pool } from "pg";
|
|
4
3
|
export type Protocol = "http" | "https";
|
|
5
|
-
/** What each login sets on top of what every instance shares. */
|
|
6
|
-
export type ExtraOptions = Omit<BetterAuthOptions, "database" | "secret" | "secrets" | "basePath" | "baseURL">;
|
|
4
|
+
/** What each login sets on top of what every instance shares; the rate limit is the tables' (`TABLE_OPTIONS`). */
|
|
5
|
+
export type ExtraOptions = Omit<BetterAuthOptions, "database" | "secret" | "secrets" | "basePath" | "baseURL" | "rateLimit">;
|
|
6
|
+
/** The schema each login's tables are in, on the company's database (`db/visitors.ts`, `db/staff.ts`). */
|
|
7
|
+
export declare const SCHEMAS: {
|
|
8
|
+
readonly visitors: "better_auth";
|
|
9
|
+
readonly staff: "better_auth_staff";
|
|
10
|
+
};
|
|
11
|
+
type Schema = (typeof SCHEMAS)[keyof typeof SCHEMAS];
|
|
7
12
|
export interface BetterAuthSetup<O extends ExtraOptions> {
|
|
8
|
-
|
|
13
|
+
/** The pool the app's client runs on (`LoginContext.database`): one instance per pool it gives. */
|
|
14
|
+
database(): Promise<Pool>;
|
|
9
15
|
/** The app's key for this login, 32 bytes as hex (`LoginContext.key`). */
|
|
10
16
|
key: string;
|
|
11
|
-
/** The schema its tables are in
|
|
12
|
-
schema:
|
|
17
|
+
/** The schema its tables are in (`SCHEMAS`). */
|
|
18
|
+
schema: Schema;
|
|
13
19
|
/** Where its routes are: `/auth/better-auth`. */
|
|
14
20
|
basePath: string;
|
|
15
21
|
/** The hosts each protocol's instance answers, as Better Auth's `allowedHosts` takes them. */
|
|
@@ -18,77 +24,137 @@ export interface BetterAuthSetup<O extends ExtraOptions> {
|
|
|
18
24
|
options: O;
|
|
19
25
|
}
|
|
20
26
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
27
|
+
* What shapes the tables beyond Better Auth's own, the same for both logins and laid over theirs,
|
|
28
|
+
* as `db/tables.ts` declares them: the user's `github` column (the GitHub login: never a person's
|
|
29
|
+
* input, so only the login sets it), and the rate limit's table (`rateLimit.storage: "database"`,
|
|
30
|
+
* so a limit holds across processes and requests). The plugins they run (the email code, magic
|
|
31
|
+
* links) keep no tables of their own.
|
|
24
32
|
*/
|
|
25
|
-
export declare
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
33
|
+
export declare const TABLE_OPTIONS: {
|
|
34
|
+
user: {
|
|
35
|
+
additionalFields: {
|
|
36
|
+
github: {
|
|
37
|
+
type: "string";
|
|
38
|
+
required: boolean;
|
|
39
|
+
input: boolean;
|
|
40
|
+
};
|
|
29
41
|
};
|
|
30
|
-
|
|
31
|
-
|
|
42
|
+
};
|
|
43
|
+
rateLimit: {
|
|
44
|
+
storage: "database";
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Better Auth on the company's database, as a function of the request's protocol: the instance
|
|
49
|
+
* for that protocol on the pool `database` gives now, made on its first use (one per pool and
|
|
50
|
+
* protocol, kept as long as the pool is). Throws when the key is not one the app derived; its
|
|
51
|
+
* first use on a pool throws when the schema's tables are still not there, or behind this
|
|
52
|
+
* version's, a minute after a worker starting beside the app should have made them
|
|
53
|
+
* (`prepareBetterAuth`).
|
|
54
|
+
*/
|
|
55
|
+
export declare function openBetterAuth<O extends ExtraOptions>({ database, key, schema, basePath, hosts, options, }: BetterAuthSetup<O>): (protocol: Protocol) => Promise<import("better-auth").Auth<{
|
|
56
|
+
rateLimit: {
|
|
57
|
+
storage: "database";
|
|
58
|
+
enabled: boolean;
|
|
59
|
+
};
|
|
60
|
+
logger: {
|
|
61
|
+
level: "warn";
|
|
62
|
+
};
|
|
63
|
+
} & O & {
|
|
64
|
+
user: {
|
|
65
|
+
modelName?: "user" | import("better-auth").LiteralString | undefined;
|
|
66
|
+
fields?: Partial<Record<"createdAt" | "email" | "emailVerified" | "image" | "name" | "updatedAt", string>> | undefined;
|
|
67
|
+
validateUserInfo?: (data: {
|
|
68
|
+
user: Partial<import("better-auth").User> & Record<string, unknown>;
|
|
69
|
+
source: import("better-auth").ValidateUserInfoSource;
|
|
70
|
+
}, context: import("better-auth").GenericEndpointContext) => import("better-auth").Awaitable<void | import("better-auth").ValidateUserInfoResult>;
|
|
71
|
+
changeEmail?: {
|
|
72
|
+
enabled: boolean;
|
|
73
|
+
sendChangeEmailConfirmation?: (data: {
|
|
74
|
+
user: import("better-auth").User;
|
|
75
|
+
newEmail: string;
|
|
76
|
+
url: string;
|
|
77
|
+
token: string;
|
|
78
|
+
}, request?: Request) => Promise<void>;
|
|
79
|
+
updateEmailWithoutVerification?: boolean;
|
|
32
80
|
};
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
81
|
+
deleteUser?: {
|
|
82
|
+
enabled?: boolean;
|
|
83
|
+
sendDeleteAccountVerification?: (data: {
|
|
84
|
+
user: import("better-auth").User;
|
|
85
|
+
url: string;
|
|
86
|
+
token: string;
|
|
87
|
+
}, request?: Request) => Promise<void>;
|
|
88
|
+
beforeDelete?: (user: import("better-auth").User, request?: Request) => Promise<void>;
|
|
89
|
+
afterDelete?: (user: import("better-auth").User, request?: Request) => Promise<void>;
|
|
90
|
+
deleteTokenExpiresIn?: number;
|
|
39
91
|
};
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
baseURL: {
|
|
47
|
-
allowedHosts: string[];
|
|
48
|
-
protocol: Protocol;
|
|
92
|
+
additionalFields: {
|
|
93
|
+
github: {
|
|
94
|
+
type: "string";
|
|
95
|
+
required: boolean;
|
|
96
|
+
input: boolean;
|
|
97
|
+
};
|
|
49
98
|
};
|
|
50
|
-
|
|
99
|
+
};
|
|
100
|
+
database: (options: BetterAuthOptions) => import("better-auth").DBAdapter<BetterAuthOptions>;
|
|
101
|
+
secrets: {
|
|
102
|
+
version: number;
|
|
103
|
+
value: string;
|
|
104
|
+
}[];
|
|
105
|
+
secret: string;
|
|
106
|
+
basePath: string;
|
|
107
|
+
baseURL: {
|
|
108
|
+
allowedHosts: string[];
|
|
109
|
+
protocol: Protocol;
|
|
110
|
+
};
|
|
111
|
+
telemetry: {
|
|
112
|
+
enabled: boolean;
|
|
113
|
+
};
|
|
114
|
+
advanced: {
|
|
115
|
+
disableCSRFCheck?: boolean | undefined;
|
|
116
|
+
crossSubDomainCookies?: {
|
|
51
117
|
enabled: boolean;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
} | undefined;
|
|
60
|
-
cookies?: {
|
|
61
|
-
[key: string]: {
|
|
62
|
-
name?: string;
|
|
63
|
-
attributes?: import("better-auth").CookieOptions;
|
|
64
|
-
};
|
|
65
|
-
} | undefined;
|
|
66
|
-
defaultCookieAttributes?: import("better-auth").CookieOptions | undefined;
|
|
67
|
-
cookiePrefix?: string | undefined;
|
|
68
|
-
database?: {
|
|
69
|
-
defaultFindManyLimit?: number;
|
|
70
|
-
generateId?: import("better-auth").GenerateIdFn | false | "serial" | "uuid";
|
|
71
|
-
joins?: boolean;
|
|
72
|
-
validateSchema?: boolean;
|
|
73
|
-
} | undefined;
|
|
74
|
-
trustedProxyHeaders?: boolean | undefined;
|
|
75
|
-
backgroundTasks?: {
|
|
76
|
-
handler: (promise: Promise<unknown>) => void;
|
|
77
|
-
};
|
|
78
|
-
skipTrailingSlashes?: boolean;
|
|
79
|
-
ipAddress: {
|
|
80
|
-
ipAddressHeaders?: string[];
|
|
81
|
-
disableIpTracking?: boolean;
|
|
82
|
-
ipv6Subnet?: number;
|
|
83
|
-
trustedProxies?: string[];
|
|
118
|
+
additionalCookies?: string[];
|
|
119
|
+
domain?: string;
|
|
120
|
+
} | undefined;
|
|
121
|
+
cookies?: {
|
|
122
|
+
[key: string]: {
|
|
123
|
+
name?: string;
|
|
124
|
+
attributes?: import("better-auth").CookieOptions;
|
|
84
125
|
};
|
|
85
|
-
|
|
86
|
-
|
|
126
|
+
} | undefined;
|
|
127
|
+
defaultCookieAttributes?: import("better-auth").CookieOptions | undefined;
|
|
128
|
+
cookiePrefix?: string | undefined;
|
|
129
|
+
database?: {
|
|
130
|
+
defaultFindManyLimit?: number;
|
|
131
|
+
generateId?: import("better-auth").GenerateIdFn | false | "serial" | "uuid";
|
|
132
|
+
joins?: boolean;
|
|
133
|
+
validateSchema?: boolean;
|
|
134
|
+
} | undefined;
|
|
135
|
+
trustedProxyHeaders?: boolean | undefined;
|
|
136
|
+
backgroundTasks?: {
|
|
137
|
+
handler: (promise: Promise<unknown>) => void;
|
|
87
138
|
};
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
139
|
+
skipTrailingSlashes?: boolean;
|
|
140
|
+
ipAddress: {
|
|
141
|
+
ipAddressHeaders?: string[];
|
|
142
|
+
disableIpTracking?: boolean;
|
|
143
|
+
ipv6Subnet?: number;
|
|
144
|
+
trustedProxies?: string[];
|
|
145
|
+
};
|
|
146
|
+
useSecureCookies: boolean;
|
|
147
|
+
disableOriginCheck: boolean;
|
|
148
|
+
};
|
|
149
|
+
}>>;
|
|
150
|
+
/**
|
|
151
|
+
* Makes the visitor login's tables (`better_auth`) on the company's database: the connector's
|
|
152
|
+
* `prepare`, which the worker runs at its start on the database's direct URL. Idempotent: a
|
|
153
|
+
* second run changes nothing.
|
|
154
|
+
*/
|
|
155
|
+
export declare const prepareBetterAuth: (databaseUrl: string) => Promise<void>;
|
|
156
|
+
/** Makes the staff login's tables (`better_auth_staff`), as `prepareBetterAuth` the visitors': the launcher's worker runs it, since no config names that login. */
|
|
157
|
+
export declare const prepareBetterAuthStaff: (databaseUrl: string) => Promise<void>;
|
|
92
158
|
/** A request's protocol: https when it came over TLS or through a proxy that says so (`x-forwarded-proto`). */
|
|
93
159
|
export declare const protocolOf: (request: Request) => Protocol;
|
|
94
160
|
/**
|
|
@@ -636,14 +702,6 @@ export declare const emailCode: (sendCode?: (email: string, code: string) => Pro
|
|
|
636
702
|
};
|
|
637
703
|
/** Whether each redirect a request names is a path on its own host: `/x`, never `//x` or another origin. */
|
|
638
704
|
export declare const localRedirects: (url: URL) => boolean;
|
|
639
|
-
/** The user's `github` column, the GitHub login: never a person's input, so only the login sets it. */
|
|
640
|
-
export declare const GITHUB_FIELD: {
|
|
641
|
-
github: {
|
|
642
|
-
type: "string";
|
|
643
|
-
required: boolean;
|
|
644
|
-
input: boolean;
|
|
645
|
-
};
|
|
646
|
-
};
|
|
647
705
|
/** A user row, as far as who it vouches for reads it. */
|
|
648
706
|
export interface User {
|
|
649
707
|
email: string;
|
|
@@ -655,3 +713,4 @@ export declare const identityOf: (user: User) => {
|
|
|
655
713
|
email?: string | undefined;
|
|
656
714
|
github?: string | undefined;
|
|
657
715
|
};
|
|
716
|
+
export {};
|
package/dist/instance.js
CHANGED
|
@@ -1,35 +1,84 @@
|
|
|
1
|
-
import { CLIENT_IP_HEADER, requestOrigin } from "@sanoma-ai/workflows";
|
|
1
|
+
import { CLIENT_IP_HEADER, errorMessage, requestOrigin } from "@sanoma-ai/workflows";
|
|
2
|
+
import { applyMigrations, databaseOn, migrationsApplied, pgCode, underPreparationLock } from "@sanoma-ai/workflows/db";
|
|
2
3
|
import { betterAuth } from "better-auth";
|
|
3
|
-
import {
|
|
4
|
+
import { drizzleAdapter } from "better-auth/adapters/drizzle";
|
|
4
5
|
import { emailOTP } from "better-auth/plugins/email-otp";
|
|
5
|
-
import { PostgresDialect } from "kysely";
|
|
6
6
|
import { setTimeout as delay } from "node:timers/promises";
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
import * as staff from "./db/staff.js";
|
|
8
|
+
import * as visitors from "./db/visitors.js";
|
|
9
|
+
import staffJournal from "../drizzle/staff/meta/_journal.json" with { type: "json" };
|
|
10
|
+
import visitorsJournal from "../drizzle/visitors/meta/_journal.json" with { type: "json" };
|
|
11
|
+
/** The schema each login's tables are in, on the company's database (`db/visitors.ts`, `db/staff.ts`). */
|
|
12
|
+
export const SCHEMAS = { visitors: visitors.schema.schemaName, staff: staff.schema.schemaName };
|
|
13
|
+
/**
|
|
14
|
+
* Each schema's login: its tables (its `db/` module, Better Auth's models by name, as its Drizzle
|
|
15
|
+
* adapter reads them) and their generated migrations, whose journal tables are the runtime's
|
|
16
|
+
* neighbours in the schema `drizzle`.
|
|
17
|
+
*/
|
|
18
|
+
const LOGINS = {
|
|
19
|
+
[SCHEMAS.visitors]: {
|
|
20
|
+
tables: visitors,
|
|
21
|
+
migrations: {
|
|
22
|
+
folder: () => new URL("../drizzle/visitors/", import.meta.url),
|
|
23
|
+
table: "__drizzle_migrations_better_auth",
|
|
24
|
+
journal: visitorsJournal,
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
[SCHEMAS.staff]: {
|
|
28
|
+
tables: staff,
|
|
29
|
+
migrations: {
|
|
30
|
+
folder: () => new URL("../drizzle/staff/", import.meta.url),
|
|
31
|
+
table: "__drizzle_migrations_better_auth_staff",
|
|
32
|
+
journal: staffJournal,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* What shapes the tables beyond Better Auth's own, the same for both logins and laid over theirs,
|
|
38
|
+
* as `db/tables.ts` declares them: the user's `github` column (the GitHub login: never a person's
|
|
39
|
+
* input, so only the login sets it), and the rate limit's table (`rateLimit.storage: "database"`,
|
|
40
|
+
* so a limit holds across processes and requests). The plugins they run (the email code, magic
|
|
41
|
+
* links) keep no tables of their own.
|
|
42
|
+
*/
|
|
43
|
+
export const TABLE_OPTIONS = {
|
|
44
|
+
user: { additionalFields: { github: { type: "string", required: false, input: false } } },
|
|
45
|
+
rateLimit: { storage: "database" },
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Each database and schema found prepared, for the process's life: a pool that finds its schema
|
|
49
|
+
* prepared spares every pool on that database the check after it. A check in flight is its own
|
|
50
|
+
* pool's and no one else's (on a Worker a request's pool goes with the request), so nothing waits
|
|
51
|
+
* on another request's work, and a failed check leaves nothing behind.
|
|
52
|
+
*/
|
|
53
|
+
const prepared = new Set();
|
|
54
|
+
/** What a pool connects to, as the key a check is remembered by: its connection string, else its host and database. */
|
|
55
|
+
function databaseOf(pool) {
|
|
56
|
+
const { connectionString, host, port, database } = pool.options;
|
|
57
|
+
return connectionString ?? `${host}:${port}/${database}`;
|
|
58
|
+
}
|
|
59
|
+
/** How long an opening login waits for a worker starting beside it to prepare the schema, and how often it looks. */
|
|
60
|
+
const PREPARED_WAIT_MS = 60_000;
|
|
61
|
+
const PREPARED_POLL_MS = 1_000;
|
|
10
62
|
/**
|
|
11
|
-
*
|
|
12
|
-
* protocol
|
|
13
|
-
* key is not one the app derived
|
|
63
|
+
* Better Auth on the company's database, as a function of the request's protocol: the instance
|
|
64
|
+
* for that protocol on the pool `database` gives now, made on its first use (one per pool and
|
|
65
|
+
* protocol, kept as long as the pool is). Throws when the key is not one the app derived; its
|
|
66
|
+
* first use on a pool throws when the schema's tables are still not there, or behind this
|
|
67
|
+
* version's, a minute after a worker starting beside the app should have made them
|
|
68
|
+
* (`prepareBetterAuth`).
|
|
14
69
|
*/
|
|
15
|
-
export
|
|
70
|
+
export function openBetterAuth({ database, key, schema, basePath, hosts, options, }) {
|
|
16
71
|
// Never Better Auth's own fallback (an environment variable, or its default secret).
|
|
17
72
|
if (!/^[0-9a-f]{64}$/.test(key))
|
|
18
73
|
throw new Error("better-auth: the app gives no key to sign cookies with");
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
// On only in production by default; in memory, per process.
|
|
23
|
-
rateLimit: { enabled: true },
|
|
74
|
+
const optionsFor = (pool, protocol) => ({
|
|
75
|
+
// On only in production by default; its counts in the schema's table, never in memory.
|
|
76
|
+
rateLimit: { enabled: true, ...TABLE_OPTIONS.rateLimit },
|
|
24
77
|
logger: { level: "warn" },
|
|
25
78
|
...options,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
type: "postgres",
|
|
30
|
-
schemaName: schema,
|
|
31
|
-
transaction: true,
|
|
32
|
-
},
|
|
79
|
+
user: { ...options.user, ...TABLE_OPTIONS.user },
|
|
80
|
+
// The schema's own tables, so no search_path, which the URL's own `options` could undo.
|
|
81
|
+
database: drizzleAdapter(databaseOn(pool), { provider: "pg", schema: LOGINS[schema].tables, transaction: true }),
|
|
33
82
|
// `secrets` over `secret`, else BETTER_AUTH_SECRETS in the environment would win.
|
|
34
83
|
secrets: [{ version: 1, value: key }],
|
|
35
84
|
secret: key,
|
|
@@ -38,7 +87,8 @@ export async function openBetterAuth({ databaseUrl, key, schema, basePath, hosts
|
|
|
38
87
|
baseURL: { allowedHosts: [...(hosts.get(protocol) ?? [])], protocol },
|
|
39
88
|
telemetry: { enabled: false },
|
|
40
89
|
advanced: {
|
|
41
|
-
// The app sets it from the socket
|
|
90
|
+
// The app sets it from the socket, or from its host's own header; Better Auth would
|
|
91
|
+
// otherwise believe a client's X-Forwarded-For.
|
|
42
92
|
ipAddress: { ipAddressHeaders: [CLIENT_IP_HEADER] },
|
|
43
93
|
useSecureCookies: protocol === "https",
|
|
44
94
|
// Its default under NODE_ENV=test is off: the same check everywhere.
|
|
@@ -46,50 +96,76 @@ export async function openBetterAuth({ databaseUrl, key, schema, basePath, hosts
|
|
|
46
96
|
...options.advanced,
|
|
47
97
|
},
|
|
48
98
|
});
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
99
|
+
/** Each pool's instances, by protocol, for as long as the pool is referenced. */
|
|
100
|
+
const made = new WeakMap();
|
|
101
|
+
return async (protocol) => {
|
|
102
|
+
const pool = await database();
|
|
103
|
+
const found = `${databaseOf(pool)}#${schema}`;
|
|
104
|
+
if (!prepared.has(found)) {
|
|
105
|
+
await checkPrepared(pool, schema);
|
|
106
|
+
prepared.add(found);
|
|
107
|
+
}
|
|
108
|
+
let auths = made.get(pool);
|
|
109
|
+
if (!auths)
|
|
110
|
+
made.set(pool, (auths = new Map()));
|
|
111
|
+
let auth = auths.get(protocol);
|
|
112
|
+
if (!auth)
|
|
113
|
+
auths.set(protocol, (auth = betterAuth(optionsFor(pool, protocol))));
|
|
114
|
+
return auth;
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Waits for the database to have had every migration of `schema`'s tables (by its journal, as
|
|
119
|
+
* `prepareDatabase` checks the runtime's own), looking every second for a minute, since a
|
|
120
|
+
* deployment's worker starts beside its app; then refuses: the worker makes them, and the app
|
|
121
|
+
* never does.
|
|
122
|
+
*/
|
|
123
|
+
async function checkPrepared(pool, schema) {
|
|
124
|
+
const db = databaseOn(pool);
|
|
125
|
+
for (const deadline = Date.now() + PREPARED_WAIT_MS;; await delay(PREPARED_POLL_MS)) {
|
|
126
|
+
if (await migrationsApplied(db, LOGINS[schema].migrations))
|
|
127
|
+
return;
|
|
128
|
+
if (Date.now() >= deadline)
|
|
129
|
+
throw new Error(`better-auth: the database's ${schema} tables are missing or behind this version's: the worker makes them at its start, and the app never does`);
|
|
59
130
|
}
|
|
60
131
|
}
|
|
61
|
-
/**
|
|
62
|
-
function
|
|
63
|
-
|
|
64
|
-
let done = migrated.get(at);
|
|
132
|
+
/** `run` once per `key` in this process, again after it fails. */
|
|
133
|
+
function once(memo, key, run) {
|
|
134
|
+
let done = memo.get(key);
|
|
65
135
|
if (!done) {
|
|
66
|
-
done =
|
|
67
|
-
|
|
136
|
+
done = run().catch((err) => {
|
|
137
|
+
memo.delete(key);
|
|
68
138
|
throw err;
|
|
69
139
|
});
|
|
70
|
-
|
|
140
|
+
memo.set(key, done);
|
|
71
141
|
}
|
|
72
142
|
return done;
|
|
73
143
|
}
|
|
144
|
+
/** Each database and schema's migration, once per process however many workers run on it. */
|
|
145
|
+
const migrated = new Map();
|
|
146
|
+
/** Postgres's code for a schema that is already there (`duplicate_schema`). */
|
|
147
|
+
const SCHEMA_EXISTS = "42P06";
|
|
74
148
|
/**
|
|
75
|
-
*
|
|
76
|
-
*
|
|
149
|
+
* The preparation of one login's `schema`: the migrations its database has not had, once per
|
|
150
|
+
* process, under the preparation's lock across processes (the runtime's own, which makes the
|
|
151
|
+
* database first when missing): two workers starting at once both succeed, the second finding
|
|
152
|
+
* everything made. A schema with no journal is one a release before these migrations made, with
|
|
153
|
+
* Better Auth's own, of another shape: refused, naming the drop that resets it.
|
|
77
154
|
*/
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
155
|
+
const preparing = (schema) => (databaseUrl) => once(migrated, `${databaseUrl}#${schema}`, () => underPreparationLock(databaseUrl, (db) => applyMigrations(db, LOGINS[schema].migrations)).catch((err) => {
|
|
156
|
+
const why = pgCode(err) === SCHEMA_EXISTS
|
|
157
|
+
? `the schema ${schema} has no journal (drizzle.${LOGINS[schema].migrations.table}): a release before this one made it, or the journal table was lost; drop the schema (DROP SCHEMA ${schema} CASCADE; its users sign in again), or restore the journal, and start the worker again`
|
|
158
|
+
: errorMessage(err);
|
|
159
|
+
throw new Error(`better-auth: could not prepare ${schema}: ${why}`, { cause: err });
|
|
160
|
+
}));
|
|
161
|
+
/**
|
|
162
|
+
* Makes the visitor login's tables (`better_auth`) on the company's database: the connector's
|
|
163
|
+
* `prepare`, which the worker runs at its start on the database's direct URL. Idempotent: a
|
|
164
|
+
* second run changes nothing.
|
|
165
|
+
*/
|
|
166
|
+
export const prepareBetterAuth = preparing(SCHEMAS.visitors);
|
|
167
|
+
/** Makes the staff login's tables (`better_auth_staff`), as `prepareBetterAuth` the visitors': the launcher's worker runs it, since no config names that login. */
|
|
168
|
+
export const prepareBetterAuthStaff = preparing(SCHEMAS.staff);
|
|
93
169
|
/** A request's protocol: https when it came over TLS or through a proxy that says so (`x-forwarded-proto`). */
|
|
94
170
|
export const protocolOf = (request) => requestOrigin(request).startsWith("https:") ? "https" : "http";
|
|
95
171
|
/**
|
|
@@ -126,8 +202,6 @@ export const localRedirects = (url) => REDIRECTS.every((name) => {
|
|
|
126
202
|
const to = url.searchParams.get(name);
|
|
127
203
|
return to === null || (to.startsWith("/") && !to.startsWith("//") && !to.startsWith("/\\"));
|
|
128
204
|
});
|
|
129
|
-
/** The user's `github` column, the GitHub login: never a person's input, so only the login sets it. */
|
|
130
|
-
export const GITHUB_FIELD = { github: { type: "string", required: false, input: false } };
|
|
131
205
|
/** What a user row vouches for: the email when verified, the GitHub login when GitHub said it. */
|
|
132
206
|
export const identityOf = (user) => ({
|
|
133
207
|
...(user.emailVerified && { email: user.email }),
|
package/dist/instance.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instance.js","sourceRoot":"","sources":["../src/instance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"instance.js","sourceRoot":"","sources":["../src/instance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrF,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AACvH,OAAO,EAA0B,UAAU,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC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AE,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;AAC9F,CAAC,CAAC,CAAC;AASL,kGAAkG;AAClG,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAU,EAAE,EAAE,CAAC,CAAC;IACzC,GAAG,CAAC,IAAI,CAAC,aAAa,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;IAChD,GAAG,CAAC,IAAI,CAAC,MAAM,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;CAC5C,CAAC,CAAC"}
|
package/dist/login.d.ts
CHANGED
|
@@ -5,9 +5,9 @@ import type { LoginContext, LoginHalf } from "@sanoma-ai/workflows";
|
|
|
5
5
|
* (`context.social.github`), a visitor also signs up and in with GitHub (`/sign-in/social`, which
|
|
6
6
|
* joins the account of GitHub's verified email), or links it once signed in (`/link-social`), and
|
|
7
7
|
* is then said to be that GitHub login (`verify`'s `github`). Its tables are in schema
|
|
8
|
-
* `better_auth` on the company's database,
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* origin's is.
|
|
8
|
+
* `better_auth` on the company's database, which the worker makes (`prepareBetterAuth`), reached
|
|
9
|
+
* through the pool the app gives each request (`context.database`), its cookies signed with the
|
|
10
|
+
* app's key for it (`context.key`). The site's origins are its allowed hosts (a request for
|
|
11
|
+
* another host is refused) and set the cookie's `Secure` flag: an `https` origin's is.
|
|
12
12
|
*/
|
|
13
|
-
export declare function betterAuthLogin({
|
|
13
|
+
export declare function betterAuthLogin({ database, key, origins, sendCode, social }: LoginContext): LoginHalf;
|