@protobase/cli 0.49.0 → 0.49.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/cli/package.js +1 -1
- package/dist/config/build-project.js +6 -3
- package/dist/config/config-defaults.js +3 -0
- package/package.json +7 -7
- package/skills/protobase/SKILL.md +7 -1
- package/skills/protobase/references/features/sign-in-and-accounts.md +2 -0
- package/skills/protobase/references/features/start-a-project.md +6 -0
- package/skills/protobase/references/getting-started.md +13 -13
- package/skills/protobase/references/guides/deploy.md +2 -2
- package/skills/protobase/references/guides/export-a-list.md +1 -1
- package/skills/protobase/references/guides/field-type.md +1 -1
- package/skills/protobase/references/guides/first-composed-page.md +1 -1
- package/skills/protobase/references/guides/first-plugin.md +1 -1
- package/skills/protobase/references/guides/import-records.md +1 -1
- package/skills/protobase/references/guides/personal-setting.md +1 -1
- package/skills/protobase/references/guides/push-notifications.md +1 -1
- package/skills/protobase/references/guides/record-card.md +1 -1
- package/skills/protobase/references/guides/remote-resources.md +1 -1
- package/skills/protobase/references/guides/theme-an-app.md +1 -1
- package/skills/protobase/references/reference/api.md +1 -1
- package/skills/protobase/references/reference/architecture.md +4 -4
- package/skills/protobase/references/reference/auth.md +29 -2
- package/skills/protobase/references/reference/blocks.md +1 -1
- package/skills/protobase/references/reference/bottom-bar.md +1 -1
- package/skills/protobase/references/reference/cli.md +9 -9
- package/skills/protobase/references/reference/client.md +2 -2
- package/skills/protobase/references/reference/config/admin-app.md +62 -0
- package/skills/protobase/references/reference/config/api.md +164 -0
- package/skills/protobase/references/reference/config/app.md +112 -0
- package/skills/protobase/references/reference/config/files.md +99 -0
- package/skills/protobase/references/reference/config/jobs-and-events.md +267 -0
- package/skills/protobase/references/reference/config/sign-in.md +396 -0
- package/skills/protobase/references/reference/config.md +88 -70
- package/skills/protobase/references/reference/custom-components.md +2 -2
- package/skills/protobase/references/reference/data-config.md +2 -2
- package/skills/protobase/references/reference/email.md +1 -1
- package/skills/protobase/references/reference/sidebar.md +2 -2
- package/skills/protobase/references/reference/ui-config.md +5 -5
- package/skills/protobase/references/reference/user-menu.md +1 -1
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
<!-- Generated by scripts/protobase-skill.ts from website/src/content/docs/reference/config/jobs-and-events.md: run `bun run docs:skill`, do not edit. -->
|
|
2
|
+
|
|
3
|
+
# Jobs and events options
|
|
4
|
+
|
|
5
|
+
The config keys of what the app does in the background and records as it changes, jobs, events, history, webhooks and notifications, with their types and defaults, and the files where a job's run and the stores of its own go.
|
|
6
|
+
|
|
7
|
+
The keys of the app's background work and of what it keeps as records change, at the top level of [`protobase.config.ts`](../config.md).
|
|
8
|
+
|
|
9
|
+
## jobs
|
|
10
|
+
|
|
11
|
+
- **Type:** `Record<string, JobDeclaration>`
|
|
12
|
+
- **Default:** none
|
|
13
|
+
|
|
14
|
+
The app's jobs by name: what each does, its arguments, when it runs and how it retries. A name is letters, digits, `_`, `-`, `.` and `/`. What the job does is the default export of `jobs/<name>.ts`, typed with `JobRun` from `@protobase/server` and loaded the first time the job runs; a job without its file stops the app at start with an error that names the file. [Jobs](../jobs.md) shows a job's config and its `jobs/<name>.ts` side by side.
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
export default defineConfig({
|
|
18
|
+
jobs: {
|
|
19
|
+
'send-invoice': { description: 'Mails an invoice to its customer.', arguments: { invoiceId: 'integer' }, maxAttempts: 5 },
|
|
20
|
+
'daily-report': { schedule: '0 7 * * *' },
|
|
21
|
+
},
|
|
22
|
+
})
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Each job takes the keys below.
|
|
26
|
+
|
|
27
|
+
### description
|
|
28
|
+
|
|
29
|
+
- **Type:** `string`
|
|
30
|
+
|
|
31
|
+
What the job does, for the people who read the config and the failed jobs page.
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
jobs: { 'send-invoice': { description: 'Mails an invoice to its customer.' } }
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### arguments
|
|
38
|
+
|
|
39
|
+
- **Type:** `Record<string, ArgumentSpec>`, each a field type or `{ type, optional?, ... }` with that type's options
|
|
40
|
+
- **Default:** none
|
|
41
|
+
|
|
42
|
+
Its arguments by name, each a [field type](../data-config.md#field-types) such as `'bigint'`, or the type with options, such as `{ type: 'enum', values: ['day', 'week'] }` or `{ type: 'integer', optional: true }`. Each is checked when the job is enqueued and again before it runs, and no other argument is taken.
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
jobs: { 'send-report': { arguments: { period: { type: 'enum', values: ['day', 'week'] }, userId: 'text' } } }
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### maxAttempts
|
|
49
|
+
|
|
50
|
+
- **Type:** `number`
|
|
51
|
+
- **Default:** `10`
|
|
52
|
+
|
|
53
|
+
Tries before the job is kept as failed, listed in the admin app. See [Failures](../jobs.md#failures).
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
jobs: { 'send-invoice': { maxAttempts: 5 } }
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### retryDelay
|
|
60
|
+
|
|
61
|
+
- **Type:** `number | string`
|
|
62
|
+
- **Default:** `2s`
|
|
63
|
+
|
|
64
|
+
The wait before the first retry, doubling with each one: milliseconds, or text such as `30 seconds`.
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
jobs: { 'sync-crm': { retryDelay: '30 seconds' } }
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### maxRetryDelay
|
|
71
|
+
|
|
72
|
+
- **Type:** `number | string`
|
|
73
|
+
- **Default:** `1 hour`
|
|
74
|
+
|
|
75
|
+
The longest wait between two tries.
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
jobs: { 'sync-crm': { maxRetryDelay: '10 minutes' } }
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### timeout
|
|
82
|
+
|
|
83
|
+
- **Type:** `number | string`
|
|
84
|
+
- **Default:** `15 minutes`
|
|
85
|
+
|
|
86
|
+
How long one try may run before it counts as failed.
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
jobs: { 'import-products': { timeout: '1 hour' } }
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### longQueries
|
|
93
|
+
|
|
94
|
+
- **Type:** `boolean`
|
|
95
|
+
- **Default:** `false`
|
|
96
|
+
|
|
97
|
+
Its queries through `db` may run up to 30 seconds instead of the database's own limit, on a connection kept for such work: for imports, backfills, large deletes and other bulk work. See [Long queries](../../guides/api-functions.md#long-queries).
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
jobs: { 'import-products': { longQueries: true } }
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### concurrency
|
|
104
|
+
|
|
105
|
+
- **Type:** `number`
|
|
106
|
+
- **Default:** `1`
|
|
107
|
+
|
|
108
|
+
Jobs of this name running at once in each worker process.
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
jobs: { 'send-invoice': { concurrency: 4 } }
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### ordered
|
|
115
|
+
|
|
116
|
+
- **Type:** `boolean`
|
|
117
|
+
- **Default:** `false`
|
|
118
|
+
|
|
119
|
+
Jobs run one at a time per group, in the order they were enqueued, and every enqueue names its group. Turning it on or off for a job whose queue exists stops the app at start. See [Ordered groups](../jobs.md#ordered-groups).
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
jobs: { 'sync-order': { ordered: true } }
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### schedule
|
|
126
|
+
|
|
127
|
+
- **Type:** `string`, a cron expression
|
|
128
|
+
|
|
129
|
+
Runs the job on this cron schedule, such as `0 7 * * *` (with an optional seconds field first), with no payload: one run per time, however many workers run. See [Recurring jobs](../jobs.md#recurring-jobs).
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
jobs: { 'daily-report': { schedule: '0 7 * * *' } }
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### timezone
|
|
136
|
+
|
|
137
|
+
- **Type:** `string`
|
|
138
|
+
- **Default:** the config's [`timezone`](app.md#timezone), else `UTC`
|
|
139
|
+
|
|
140
|
+
The time zone `schedule` is read in, such as `Europe/Amsterdam`, so 07:00 stays 07:00 across daylight saving time.
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
jobs: { 'daily-report': { schedule: '0 7 * * *', timezone: 'Europe/Amsterdam' } }
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## events.schema
|
|
147
|
+
|
|
148
|
+
- **Type:** `string`
|
|
149
|
+
- **Default:** `changes`
|
|
150
|
+
|
|
151
|
+
The schema holding the outbox and the capture function that resources' [events](../events.md) are raised from, and the prefix of their transaction settings (`changes.actor`, `changes.capture`). Rename it when the database already has a schema by that name; lowercase letters, digits and `_`. See [How changes are captured](../events.md#how-changes-are-captured).
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
export default defineConfig({ events: { schema: 'app_changes' } })
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## history.days
|
|
158
|
+
|
|
159
|
+
- **Type:** `number`, a positive whole number
|
|
160
|
+
- **Default:** kept forever
|
|
161
|
+
|
|
162
|
+
Days a change of a resource with `.history()` is kept; a daily job deletes older ones. See [Record history](../history.md#keeping-it).
|
|
163
|
+
|
|
164
|
+
```ts
|
|
165
|
+
export default defineConfig({ history: { days: 365 } })
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## webhooks
|
|
169
|
+
|
|
170
|
+
- **Type:** `{ schema?: string; deliveryLog?: boolean; allowPrivateAddresses?: boolean }`
|
|
171
|
+
- **Default:** off; `{}` turns them on
|
|
172
|
+
|
|
173
|
+
Webhook subscriptions that people make in the admin app, kept in a table of the app's database that `protobase migration` writes. A subscription delivers as its owner, with the roles they hold now, read from the app's sign-in; a project that signs people in otherwise exports its own, `async ({ id, tenant }) => [...]`, as the default of `webhooks/owner-roles.ts`. See [Subscriptions in the admin app](../webhooks.md#subscriptions-in-the-admin-app).
|
|
174
|
+
|
|
175
|
+
```ts
|
|
176
|
+
export default defineConfig({ webhooks: {} })
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## webhooks.schema
|
|
180
|
+
|
|
181
|
+
- **Type:** `string`
|
|
182
|
+
- **Default:** `webhooks`
|
|
183
|
+
|
|
184
|
+
The schema of the subscriptions table and the deliveries view.
|
|
185
|
+
|
|
186
|
+
```ts
|
|
187
|
+
export default defineConfig({ webhooks: { schema: 'hooks' } })
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## webhooks.deliveryLog
|
|
191
|
+
|
|
192
|
+
- **Type:** `boolean`
|
|
193
|
+
- **Default:** `false`
|
|
194
|
+
|
|
195
|
+
Also keeps every try, successes too, for 30 days, listed as the Webhook delivery log.
|
|
196
|
+
|
|
197
|
+
```ts
|
|
198
|
+
export default defineConfig({ webhooks: { deliveryLog: true } })
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## webhooks.allowPrivateAddresses
|
|
202
|
+
|
|
203
|
+
- **Type:** `boolean`
|
|
204
|
+
- **Default:** `false`
|
|
205
|
+
|
|
206
|
+
Lets subscriptions send to private, loopback and link-local addresses, for development and tests. Off, a URL whose host resolves to one is refused, so a subscription cannot reach the app's own network.
|
|
207
|
+
|
|
208
|
+
```ts
|
|
209
|
+
export default defineConfig(({ command }) => ({ webhooks: { allowPrivateAddresses: command === 'dev' } }))
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## notifications
|
|
213
|
+
|
|
214
|
+
- **Type:** `{ ui?: boolean; schema?: string; devices?: { table?: string; columns?: Record<string, string> }; history?: { table?: string; columns?: Record<string, string> } }`
|
|
215
|
+
- **Default:** off; `{}` turns them on
|
|
216
|
+
|
|
217
|
+
Each user's devices and inbox: the bell in the top bar and push on their browsers, over tables that `protobase migration` writes. Web Push is on when the `PROTOBASE_VAPID_*` variables are set. See [Notifications](../notifications.md#turning-them-on).
|
|
218
|
+
|
|
219
|
+
Three files replace the built-in parts, each as its default export: `notifications/store.ts` a device store in place of the devices table, `notifications/history-store.ts` a history store in place of the history table, and `notifications/senders.ts` an array of push senders in place of the built-in ones. See [Your own parts](../notifications.md#your-own-parts).
|
|
220
|
+
|
|
221
|
+
```ts
|
|
222
|
+
export default defineConfig({ notifications: {} })
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## notifications.ui
|
|
226
|
+
|
|
227
|
+
- **Type:** `boolean`
|
|
228
|
+
- **Default:** `true`
|
|
229
|
+
|
|
230
|
+
The bell in the top bar; `false` keeps only the backend. See [Without the bell](../notifications.md#without-the-bell).
|
|
231
|
+
|
|
232
|
+
```ts
|
|
233
|
+
export default defineConfig({ notifications: { ui: false } })
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
## notifications.schema
|
|
237
|
+
|
|
238
|
+
- **Type:** `string`
|
|
239
|
+
- **Default:** `notifications`
|
|
240
|
+
|
|
241
|
+
The schema of the built-in tables.
|
|
242
|
+
|
|
243
|
+
```ts
|
|
244
|
+
export default defineConfig({ notifications: { schema: 'inbox' } })
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
## notifications.devices
|
|
248
|
+
|
|
249
|
+
- **Type:** `{ table?: string; columns?: Record<string, string> }`
|
|
250
|
+
- **Default:** `{ table: 'devices' }`
|
|
251
|
+
|
|
252
|
+
The devices table: its name, and its columns named otherwise than Protobase names them. See [Table names](../notifications.md#table-names).
|
|
253
|
+
|
|
254
|
+
```ts
|
|
255
|
+
export default defineConfig({ notifications: { devices: { table: 'push_devices', columns: { user_id: 'owner_id' } } } })
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## notifications.history
|
|
259
|
+
|
|
260
|
+
- **Type:** `{ table?: string; columns?: Record<string, string> }`
|
|
261
|
+
- **Default:** `{ table: 'history' }`
|
|
262
|
+
|
|
263
|
+
The history table, each user's inbox: its name, and its columns named otherwise than Protobase names them.
|
|
264
|
+
|
|
265
|
+
```ts
|
|
266
|
+
export default defineConfig({ notifications: { history: { table: 'inbox_items' } } })
|
|
267
|
+
```
|
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
<!-- Generated by scripts/protobase-skill.ts from website/src/content/docs/reference/config/sign-in.md: run `bun run docs:skill`, do not edit. -->
|
|
2
|
+
|
|
3
|
+
# Sign-in options
|
|
4
|
+
|
|
5
|
+
The config keys of sign-in, auth and authenticate, each with its type, default and environment variable, and the files where sign-in's hooks, mailer, mail templates and an authenticator of the project's own go.
|
|
6
|
+
|
|
7
|
+
The keys of sign-in and of how the API verifies tokens, in [`protobase.config.ts`](../config.md). The app's URL, secrets and name, which sign-in uses, are the top-level [`url`, `secret`, `previousSecrets` and `name`](app.md). How sign-in works is in [Login with Better Auth](../auth.md).
|
|
8
|
+
|
|
9
|
+
## auth
|
|
10
|
+
|
|
11
|
+
- **Type:** `AuthConfig | false`
|
|
12
|
+
- **Default:** on, with the defaults below; off when [`authenticate.jwksUrl`](#authenticatejwksurl) trusts an auth server elsewhere
|
|
13
|
+
|
|
14
|
+
Sign-in, with its store in the app's own database. `false` turns it off; an app without sign-in then verifies tokens with [`authenticate`](#authenticate) or `auth/authenticate.ts`.
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
export default defineConfig({ auth: { roles: ['admin', 'sales'], signInFirst: 'emailCode' } })
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Sign-in runs the project's own code from these files, each loaded when Protobase builds sign-in:
|
|
21
|
+
|
|
22
|
+
- `auth/hooks.ts`: the hooks, as named exports typed with `AuthHooks` from `@protobase/server`: `generateUserId`, `onUserCreated`, `generateOrganizationId`, `onOrganizationCreated`, `beforeOrganizationDeleted` and `organizationHooks`. Each gets the app's database, `{ db }`, as its last argument. See [Hooks](../auth.md#hooks).
|
|
23
|
+
- `auth/mailer.ts`: a mailer of the project's own for sign-in's mail, as its default export, in place of the SMTP mailer. See [Email](../email.md).
|
|
24
|
+
- `emails/`: the templates of sign-in's mail. See [Templates](../email.md#templates).
|
|
25
|
+
|
|
26
|
+
With [extensions](../config.md#extensions), the hooks and the mailer are those of the last folder whose config sets `auth`.
|
|
27
|
+
|
|
28
|
+
## auth.roles
|
|
29
|
+
|
|
30
|
+
- **Type:** `string[] | Record<string, string | { label: string; grants?: string[] }>`
|
|
31
|
+
- **Default:** `['admin', 'user']`
|
|
32
|
+
|
|
33
|
+
The roles users can hold. `admin` is always included. With [`organizations`](#authorganizations), give each a label, and optionally the other roles its holders may also give members. The capabilities each role has are `config/roles.ts`'s (see [Access](../access.md)). See [Roles](../auth.md#roles).
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
export default defineConfig({
|
|
37
|
+
auth: { roles: { manager: { label: 'Manager', grants: ['sales'] }, sales: 'Sales' }, organizations: true },
|
|
38
|
+
})
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## auth.defaultRole
|
|
42
|
+
|
|
43
|
+
- **Type:** `string`
|
|
44
|
+
- **Default:** none; with exactly one role besides `admin`, that role
|
|
45
|
+
|
|
46
|
+
The role of a user created without one. Without a default, and with more than one role besides `admin`, creating a user without a role is an error that asks for one.
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
export default defineConfig({ auth: { roles: ['admin', 'sales', 'warehouse'], defaultRole: 'sales' } })
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## auth.organizations
|
|
53
|
+
|
|
54
|
+
- **Type:** `true | { create?: 'admins' | 'everyone'; creatorAppRoles?: 'all' | string[]; invitationDays?: number; membershipLimit?: number; deleteRecords?: 'refuse' | 'cascade'; invitationUrl?: string }`
|
|
55
|
+
- **Default:** off: the app works as one organization
|
|
56
|
+
|
|
57
|
+
Turns on organizations: people work in one at a time, records of `.tenant` resources are scoped to it, and roles are held globally or per membership. `create` is who may create one (default `admins`), `creatorAppRoles` the roles its creator holds there (default `all`), `invitationDays` how long an invitation works (default 7), `membershipLimit` the most members (default 1000), `deleteRecords` whether deleting one is refused while it has records (`refuse`, the default) or left to the foreign keys (`cascade`), and `invitationUrl` the page an invitation opens (default `<url>/-/invitation`). Its hooks are in `auth/hooks.ts`. See [Organizations](../auth.md#organizations).
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
export default defineConfig({ auth: { organizations: { create: 'everyone', invitationDays: 14 } } })
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## auth.signUp
|
|
64
|
+
|
|
65
|
+
- **Type:** `{ role: string }`
|
|
66
|
+
- **Default:** off
|
|
67
|
+
|
|
68
|
+
Open sign-up: anyone makes their own account from the sign-in page, with `role`, after proving their address with an emailed code. Needs a mailer. `role` is one of [`roles`](#authroles) and never `admin`. Not with organizations. See [Open sign-up](../auth.md#open-sign-up).
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
export default defineConfig({ auth: { roles: ['admin', 'customer'], signUp: { role: 'customer' } } })
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## auth.signInPolicy
|
|
75
|
+
|
|
76
|
+
- **Type:** `Partial<{ password: 'allowed' | 'forbidden'; emailCode: 'allowed' | 'forbidden'; passkey: 'allowed' | 'required' | 'forbidden'; twoFactor: 'allowed' | 'required' | 'forbidden'; staffAccess: 'allowed' | 'notify' | 'forbidden'; platformSignIn: 'allowed' | 'forbidden' }>`
|
|
77
|
+
- **Default:** everything allowed
|
|
78
|
+
|
|
79
|
+
The sign-in policy that applies until an admin saves one on the Sign-in policy page, and when the saved one no longer reads. Checked at startup as an admin's save is. See [Sign-in policy](../auth.md#sign-in-policy).
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
export default defineConfig({ auth: { signInPolicy: { password: 'forbidden', twoFactor: 'required' } } })
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## auth.signInFirst
|
|
86
|
+
|
|
87
|
+
- **Type:** `'password' | 'emailCode'`
|
|
88
|
+
- **Default:** `password`
|
|
89
|
+
|
|
90
|
+
What the sign-in page leads with: the address and a password, with emailing a code below it; or the address and "Email me a sign-in code", with the password behind "Use a password". Only while the policy leaves both on. See [Emailed sign-in codes](../auth.md#emailed-sign-in-codes).
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
export default defineConfig({ auth: { signInFirst: 'emailCode' } })
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## auth.signInPerMinute
|
|
97
|
+
|
|
98
|
+
- **Type:** `number`
|
|
99
|
+
- **Default:** `5`
|
|
100
|
+
|
|
101
|
+
Sign-in attempts allowed per minute and client, and the sign-up requests allowed. See [Client addresses](../auth.md#client-addresses) for how a client is known.
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
export default defineConfig({ auth: { signInPerMinute: 10 } })
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## auth.mailer
|
|
108
|
+
|
|
109
|
+
- **Type:** `false`
|
|
110
|
+
- **Default:** SMTP with `PROTOBASE_SMTP_URL` and `PROTOBASE_MAIL_FROM`, when set
|
|
111
|
+
- **Environment variables:** `PROTOBASE_SMTP_URL`, `PROTOBASE_MAIL_FROM`
|
|
112
|
+
|
|
113
|
+
`false` turns sign-in's mail off whatever the environment says: password reset, emailed codes, sign-up, staff sign-in and invitations are then not offered. A mailer of the project's own is `auth/mailer.ts`. See [Email](../email.md#configuration).
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
export default defineConfig({ auth: { mailer: false } })
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## auth.socialProviders
|
|
120
|
+
|
|
121
|
+
- **Type:** Better Auth's `socialProviders`
|
|
122
|
+
- **Default:** none
|
|
123
|
+
|
|
124
|
+
Sign-in providers, such as `{ github: { clientId, clientSecret } }`; the callback is `<url>/api/auth/callback/<provider>`. A provider also signs up people without an account, with the default role. See [Sign-in with GitHub](../auth.md#sign-in-with-github).
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
export default defineConfig(({ env }) => ({
|
|
128
|
+
auth: { socialProviders: { github: { clientId: env.GITHUB_CLIENT_ID!, clientSecret: env.GITHUB_CLIENT_SECRET! } } },
|
|
129
|
+
}))
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## auth.encryptOAuthTokens
|
|
133
|
+
|
|
134
|
+
- **Type:** `boolean`
|
|
135
|
+
- **Default:** `false`
|
|
136
|
+
|
|
137
|
+
Encrypts the OAuth access, refresh and ID tokens kept for social sign-ins, with the app's secret.
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
export default defineConfig({ auth: { encryptOAuthTokens: true } })
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## auth.sso
|
|
144
|
+
|
|
145
|
+
- **Type:** `{ saml: { id: string; name?: string; domains: string[]; idp: { metadata: string } | { entityId: string; ssoUrl: string; certificate: string | string[] }; attributes?: { email?: string; name?: string; firstName?: string; lastName?: string } }[] }`
|
|
146
|
+
- **Default:** none
|
|
147
|
+
|
|
148
|
+
Single sign-on with SAML 2.0 identity providers. A provider signs up people without an account, with the default role, but only at its `domains`, where it also links to the account with the same address. `name` defaults to `SSO`. See [Sign-in with SAML](../auth.md#sign-in-with-saml).
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
export default defineConfig(({ env }) => ({
|
|
152
|
+
auth: { sso: { saml: [{ id: 'okta', name: 'Okta', domains: ['example.com'], idp: { metadata: env.OKTA_METADATA! } }] } },
|
|
153
|
+
}))
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## auth.signInProvider
|
|
157
|
+
|
|
158
|
+
- **Type:** `{ issuer: string; clientId: string; clientSecret: string; provider?: string; name?: string; scopes?: string[] } | false`
|
|
159
|
+
- **Default:** the provider of the environment variables below, when set
|
|
160
|
+
- **Environment variables:** `PROTOBASE_SIGN_IN_ISSUER`, `PROTOBASE_SIGN_IN_CLIENT_ID`, `PROTOBASE_SIGN_IN_CLIENT_SECRET`, and optionally `PROTOBASE_SIGN_IN_PROVIDER` and `PROTOBASE_SIGN_IN_NAME`
|
|
161
|
+
|
|
162
|
+
An OpenID Connect provider the platform adds for people who already have an account; it never signs anyone up. `provider` is its id (default `oidc`), `name` its button's name. `false` turns it off whatever the environment says. Left out when `socialProviders` has a provider with the same id. See [Platform sign-in provider](../auth.md#platform-sign-in-provider).
|
|
163
|
+
|
|
164
|
+
```ts
|
|
165
|
+
export default defineConfig({ auth: { signInProvider: false } })
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## auth.operator
|
|
169
|
+
|
|
170
|
+
- **Type:** `{ issuer: string; clientId: string; clientSecret: string; name?: string; group?: string; scopes?: string[]; acrValues?: string[]; sessionMinutes?: number } | false`
|
|
171
|
+
- **Default:** the provider of the environment variables below, when set
|
|
172
|
+
- **Environment variables:** `PROTOBASE_OPERATOR_ISSUER`, `PROTOBASE_OPERATOR_CLIENT_ID`, `PROTOBASE_OPERATOR_CLIENT_SECRET`, and optionally `PROTOBASE_OPERATOR_NAME` and `PROTOBASE_OPERATOR_GROUP`
|
|
173
|
+
|
|
174
|
+
The identity provider the operator's staff sign in with to sign in as people of this app, for support. `group` is the ID token's group that allows it (default `protobase-staff-access`), and `sessionMinutes` how long a staff session lasts (default 30, at most 240). `false` turns staff sign-in off whatever the environment says. See [Staff sign-in](../auth.md#staff-sign-in).
|
|
175
|
+
|
|
176
|
+
```ts
|
|
177
|
+
export default defineConfig({ auth: { operator: false } })
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## auth.passwordHashes
|
|
181
|
+
|
|
182
|
+
- **Type:** `'bcrypt'[]`
|
|
183
|
+
- **Default:** none
|
|
184
|
+
|
|
185
|
+
Password hashes another system wrote that sign-in accepts besides Better Auth's own, such as Supabase Auth's bcrypt. The first sign-in with one stores the password again as Better Auth hashes it. See [An existing users table](../auth.md#an-existing-users-table).
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
export default defineConfig({ auth: { passwordHashes: ['bcrypt'] } })
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## auth.leakedPasswords
|
|
192
|
+
|
|
193
|
+
- **Type:** `boolean`
|
|
194
|
+
- **Default:** `false`
|
|
195
|
+
|
|
196
|
+
Refuses a new password that appears in a known data breach, by Have I Been Pwned's list. Only the first five characters of the password's SHA-1 hash leave the server. See [Leaked passwords](../auth.md#leaked-passwords).
|
|
197
|
+
|
|
198
|
+
```ts
|
|
199
|
+
export default defineConfig({ auth: { leakedPasswords: true } })
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## auth.users
|
|
203
|
+
|
|
204
|
+
- **Type:** `{ table?: string; columns?: Record<string, string>; metadata?: string }`
|
|
205
|
+
- **Default:** the table `protobase auth migration` makes
|
|
206
|
+
|
|
207
|
+
The user table, when another system made it, such as Supabase's `auth.users`: its name, the columns named otherwise than Protobase names them, and a JSON column for each user's metadata. See [An existing users table](../auth.md#an-existing-users-table).
|
|
208
|
+
|
|
209
|
+
```ts
|
|
210
|
+
export default defineConfig({
|
|
211
|
+
auth: { schema: 'auth', users: { table: 'users', columns: { role: 'app_role' }, metadata: 'raw_user_meta_data' } },
|
|
212
|
+
})
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
## auth.schema
|
|
216
|
+
|
|
217
|
+
- **Type:** `string`
|
|
218
|
+
- **Default:** `auth`
|
|
219
|
+
|
|
220
|
+
The schema of the auth store in the app's database. See [Admin store](../auth.md#admin-store).
|
|
221
|
+
|
|
222
|
+
```ts
|
|
223
|
+
export default defineConfig({ auth: { schema: 'accounts' } })
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
## auth.generateUserId
|
|
227
|
+
|
|
228
|
+
- **Type:** `'uuid'`
|
|
229
|
+
- **Default:** Better Auth's random 32-character text
|
|
230
|
+
|
|
231
|
+
`'uuid'` gives new users a random UUID, and makes every id column of the store a `uuid`. To take ids from the app instead, such as its own users sequence, export `generateUserId` from `auth/hooks.ts`.
|
|
232
|
+
|
|
233
|
+
```ts
|
|
234
|
+
export default defineConfig({ auth: { generateUserId: 'uuid' } })
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## auth.origins
|
|
238
|
+
|
|
239
|
+
- **Type:** `string[]`
|
|
240
|
+
- **Default:** `PROTOBASE_ORIGINS`, comma separated; none otherwise
|
|
241
|
+
- **Environment variable:** `PROTOBASE_ORIGINS`
|
|
242
|
+
|
|
243
|
+
The other origins the app is served on, besides `url`. A request to one is answered for that host: its sign-in callbacks and the links it mails stay there, and passkeys work on every origin. Tokens keep `url` as issuer. See [Several origins](../auth.md#several-origins).
|
|
244
|
+
|
|
245
|
+
```ts
|
|
246
|
+
export default defineConfig({ auth: { origins: ['https://admin.shop.com'] } })
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
## auth.passkeyDomain
|
|
250
|
+
|
|
251
|
+
- **Type:** `string`
|
|
252
|
+
- **Default:** `PROTOBASE_PASSKEY_DOMAIN`, else the host of `url`
|
|
253
|
+
- **Environment variable:** `PROTOBASE_PASSKEY_DOMAIN`
|
|
254
|
+
|
|
255
|
+
The host new passkeys are made for: the host of `url` or of one of `origins`. Each passkey keeps the one it was made for, so changing it breaks none. See [Passkeys](../auth.md#passkeys).
|
|
256
|
+
|
|
257
|
+
```ts
|
|
258
|
+
export default defineConfig({ auth: { origins: ['https://admin.shop.com'], passkeyDomain: 'admin.shop.com' } })
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
## auth.trustedOrigins
|
|
262
|
+
|
|
263
|
+
- **Type:** `string[]`
|
|
264
|
+
- **Default:** `PROTOBASE_TRUSTED_ORIGINS`, comma separated
|
|
265
|
+
- **Environment variable:** `PROTOBASE_TRUSTED_ORIGINS`
|
|
266
|
+
|
|
267
|
+
Extra origins that may call the auth endpoints, such as the exact host of a dev tunnel; no wildcard is trusted. `url` and `origins` always are. Set in the config, it replaces the variable's list.
|
|
268
|
+
|
|
269
|
+
```ts
|
|
270
|
+
export default defineConfig(({ env }) => ({
|
|
271
|
+
auth: { trustedOrigins: env.TUNNEL_URL ? [env.TUNNEL_URL] : undefined },
|
|
272
|
+
}))
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
## auth.mcp
|
|
276
|
+
|
|
277
|
+
- **Type:** `true | { path?: string; connectPage?: string }`
|
|
278
|
+
- **Default:** off
|
|
279
|
+
|
|
280
|
+
Turns on the OAuth provider for MCP clients, and with it the MCP endpoint: a client registers itself, the person signs in and allows it on the connect page, and the client gets tokens for the MCP endpoint only. `path` is the endpoint's (default `/api/mcp`), `connectPage` the page's (default `/-/connect`). Needs an https `url`, or localhost, and the OAuth tables from `protobase auth migration`. The endpoint's tools are [`mcpEndpoint`](api.md#mcpendpoint). See [MCP](../mcp.md#turning-it-on).
|
|
281
|
+
|
|
282
|
+
```ts
|
|
283
|
+
export default defineConfig({ auth: { mcp: true } })
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
## authenticate
|
|
287
|
+
|
|
288
|
+
- **Type:** `AuthenticateSettings`
|
|
289
|
+
- **Default:** the tokens of `auth`
|
|
290
|
+
|
|
291
|
+
How the API verifies tokens: the app's own, those of an auth server elsewhere, and those of other Protobase apps it admits. An authenticator of the project's own, such as `jwtAuthenticator(...)` for tokens of another system, is the default export of `auth/authenticate.ts`, which replaces this key. See [Tokens and roles](../auth.md#tokens-and-roles).
|
|
292
|
+
|
|
293
|
+
```ts
|
|
294
|
+
export default defineConfig({ authenticate: { tenant: 'acme' } })
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
## authenticate.tenant
|
|
298
|
+
|
|
299
|
+
- **Type:** `string | number`
|
|
300
|
+
|
|
301
|
+
The one tenant everyone works in, for an app without organizations; never read from the token.
|
|
302
|
+
|
|
303
|
+
```ts
|
|
304
|
+
export default defineConfig({ authenticate: { tenant: 1 } })
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
## authenticate.jwksUrl
|
|
308
|
+
|
|
309
|
+
- **Type:** `string`
|
|
310
|
+
|
|
311
|
+
The key set of an auth server elsewhere, for an API that runs apart from it. Needs `issuer`. Set without `auth`, it turns the app's own sign-in off.
|
|
312
|
+
|
|
313
|
+
```ts
|
|
314
|
+
export default defineConfig({
|
|
315
|
+
authenticate: { jwksUrl: 'https://auth.example.com/api/auth/jwks', issuer: 'https://auth.example.com' },
|
|
316
|
+
})
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
## authenticate.issuer
|
|
320
|
+
|
|
321
|
+
- **Type:** `string`
|
|
322
|
+
- **Default:** the app's `url`
|
|
323
|
+
|
|
324
|
+
The issuer the tokens must name; it is also their audience unless `audience` names another.
|
|
325
|
+
|
|
326
|
+
```ts
|
|
327
|
+
export default defineConfig({ authenticate: { jwksUrl: 'https://auth.example.com/api/auth/jwks', issuer: 'https://auth.example.com' } })
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
## authenticate.audience
|
|
331
|
+
|
|
332
|
+
- **Type:** `string`
|
|
333
|
+
- **Default:** `issuer`
|
|
334
|
+
|
|
335
|
+
The audience the tokens must name.
|
|
336
|
+
|
|
337
|
+
```ts
|
|
338
|
+
export default defineConfig({ authenticate: { jwksUrl: 'https://auth.example.com/api/auth/jwks', issuer: 'https://auth.example.com', audience: 'https://api.example.com' } })
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
## authenticate.organizations
|
|
342
|
+
|
|
343
|
+
- **Type:** `boolean`
|
|
344
|
+
- **Default:** read from `auth`
|
|
345
|
+
|
|
346
|
+
Whether the tokens carry organizations. Needed with `jwksUrl` only.
|
|
347
|
+
|
|
348
|
+
```ts
|
|
349
|
+
export default defineConfig({ authenticate: { jwksUrl: 'https://auth.example.com/api/auth/jwks', issuer: 'https://auth.example.com', organizations: true } })
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
## authenticate.cache
|
|
353
|
+
|
|
354
|
+
- **Type:** `{ refreshMs?: number; minReloadMs?: number }`
|
|
355
|
+
- **Default:** `{ refreshMs: 600000, minReloadMs: 30000 }`
|
|
356
|
+
|
|
357
|
+
How long the key set is kept: reloaded whole every `refreshMs`, so removed keys stop working, and when a token names an unknown key, at most every `minReloadMs`.
|
|
358
|
+
|
|
359
|
+
```ts
|
|
360
|
+
export default defineConfig({ authenticate: { cache: { refreshMs: 60_000 } } })
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
## authenticate.apps
|
|
364
|
+
|
|
365
|
+
- **Type:** `{ issuer: string; roles: Record<string, string | string[]>; tenant?: string | number }[]`
|
|
366
|
+
- **Default:** none
|
|
367
|
+
|
|
368
|
+
Other Protobase apps whose signed-in users this API admits with their own tokens, so their admin apps can draw its resources. `issuer` is that app's `url`, `roles` maps its global roles to this app's (a role it does not list is dropped, and a user left with none is refused), and `tenant` is where its users work. See [Users of another app](../auth.md#users-of-another-app).
|
|
369
|
+
|
|
370
|
+
```ts
|
|
371
|
+
export default defineConfig({
|
|
372
|
+
authenticate: { apps: [{ issuer: 'https://admin.shop.com', roles: { admin: 'shop' } }] },
|
|
373
|
+
})
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
## signingKeyDays
|
|
377
|
+
|
|
378
|
+
- **Type:** `number`
|
|
379
|
+
- **Default:** `30`
|
|
380
|
+
|
|
381
|
+
Days a token signing key signs; the first token after that makes a new key. A month bounds how long a leaked key could sign, and keeps the key set to a few keys. A top-level key, beside `auth`. See [Signing keys](../auth.md#signing-keys).
|
|
382
|
+
|
|
383
|
+
```ts
|
|
384
|
+
export default defineConfig({ signingKeyDays: 90 })
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
## signingKeyGraceDays
|
|
388
|
+
|
|
389
|
+
- **Type:** `number`, at least `1`
|
|
390
|
+
- **Default:** `7`
|
|
391
|
+
|
|
392
|
+
Days a replaced signing key stays in the key set, so the tokens it signed keep verifying until they expire; it is deleted after that. A week is far longer than any token lasts, a day at most, so an API that caches the key set never refuses a token signed just before a rotation. A top-level key, beside `auth`.
|
|
393
|
+
|
|
394
|
+
```ts
|
|
395
|
+
export default defineConfig({ signingKeyGraceDays: 14 })
|
|
396
|
+
```
|