@protobase/cli 0.46.3 → 0.46.5
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/package.json +6 -6
- package/skills/protobase/SKILL.md +1 -0
- package/skills/protobase/references/features/composed-pages.md +1 -0
- package/skills/protobase/references/features/sign-in-and-accounts.md +1 -0
- package/skills/protobase/references/guides/personal-setting.md +117 -0
- package/skills/protobase/references/reference/access.md +1 -1
- package/skills/protobase/references/reference/auth.md +68 -5
- package/skills/protobase/references/reference/blocks.md +100 -1
- package/skills/protobase/references/reference/client.md +1 -1
- package/skills/protobase/references/reference/layouts.md +2 -2
- package/skills/protobase/references/reference/user-menu.md +2 -2
package/dist/cli/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.46.
|
|
3
|
+
"version": "0.46.5",
|
|
4
4
|
"description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
"@better-auth/core": "^1.7.12",
|
|
37
37
|
"@hono/node-server": "^2.1.3",
|
|
38
38
|
"@hono/vite-dev-server": "^0.26.1",
|
|
39
|
-
"@protobase/layout": "0.46.
|
|
40
|
-
"@protobase/query": "0.46.
|
|
41
|
-
"@protobase/schema": "0.46.
|
|
42
|
-
"@protobase/server": "0.46.
|
|
43
|
-
"@protobase/ui": "0.46.
|
|
39
|
+
"@protobase/layout": "0.46.5",
|
|
40
|
+
"@protobase/query": "0.46.5",
|
|
41
|
+
"@protobase/schema": "0.46.5",
|
|
42
|
+
"@protobase/server": "0.46.5",
|
|
43
|
+
"@protobase/ui": "0.46.5",
|
|
44
44
|
"@react-email/render": "^2.1.0",
|
|
45
45
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
46
46
|
"@tailwindcss/vite": "^4.3.3",
|
|
@@ -57,6 +57,7 @@ Guides:
|
|
|
57
57
|
- When importing records from a spreadsheet → read [Importing records from a spreadsheet](references/guides/import-records.md)
|
|
58
58
|
- When telling users about a change, in the bell and as push on their browsers → read [Send notifications](references/guides/push-notifications.md)
|
|
59
59
|
- When replacing a resource's create form with a page of your own → read [A create page of your own](references/guides/create-page.md)
|
|
60
|
+
- When letting each person set a choice of their own, such as which emails they get → read [Add a personal setting](references/guides/personal-setting.md)
|
|
60
61
|
- When running the app on iOS or Android → read [A mobile app](references/guides/mobile-app.md)
|
|
61
62
|
|
|
62
63
|
Reference:
|
|
@@ -15,4 +15,5 @@ Pages of your own, built from blocks in a JSX layout.
|
|
|
15
15
|
- [Record cards](../reference/blocks.md#recordcards): Full-width cards with fields and buttons, stacked or in a carousel.
|
|
16
16
|
- [Chart block](../reference/blocks.md#chart): Counts, sums or averages by value or by date, as bars, lines or a donut, and over time split by a second field.
|
|
17
17
|
- [Buttons and forms](../reference/blocks.md#behaviour): Buttons for named actions, and create or edit forms in a dialog.
|
|
18
|
+
- [Settings block](../reference/blocks.md#settings): Each person's own settings from a resource with one record per person, saved as they change, with defaults until the first save.
|
|
18
19
|
- [Users block](../reference/blocks.md#users): User management on any page: find users, set roles, block them and invite by email.
|
|
@@ -10,6 +10,7 @@ Sign-in methods, users, roles, organizations and tokens.
|
|
|
10
10
|
- [Users page](../reference/auth.md#users-page): Admins find people, set roles, block them, add accounts and invite people by email.
|
|
11
11
|
- [Password reset](../reference/auth.md#password-reset): People reset a forgotten password through an emailed link.
|
|
12
12
|
- [Emailed sign-in codes](../reference/auth.md#emailed-sign-in-codes): People sign in with a code sent to their email. An address with no account is emailed that it has none, so the person tries the one they signed up with.
|
|
13
|
+
- [Changing the address](../reference/auth.md#changing-the-address): People move their account to a new email address from the account page, once they enter the code sent there.
|
|
13
14
|
- [Open sign-up](../reference/auth.md#open-sign-up): Anyone can create an account after confirming an emailed code.
|
|
14
15
|
- [Passkeys](../reference/auth.md#passkeys): People sign in with their device's face or fingerprint unlock, or with a security key.
|
|
15
16
|
- [Two-factor authentication](../reference/auth.md#two-factor-authentication): A second step with an authenticator app, backup codes or emailed codes.
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
<!-- Generated by scripts/protobase-skill.ts from website/src/content/docs/guides/personal-setting.mdx: run `bun run docs:skill`, do not edit. -->
|
|
2
|
+
|
|
3
|
+
# Add a personal setting
|
|
4
|
+
|
|
5
|
+
A choice each person makes for themselves, such as which emails they get, in a tab of the account page, from a table, a resource and roles, with no UI code.
|
|
6
|
+
|
|
7
|
+
Rijnland's accountants want an email for each invoice that passes its due date; the warehouse would rather get none. That is a choice each person makes for themselves, so it belongs on their [account page](../reference/auth.md#account-page), and the fields the page shows come from a resource like any other. This guide adds it to the ERP example (`examples/erp`) in four steps: a table, a resource, roles and a tab.
|
|
8
|
+
|
|
9
|
+
## 1. A table with one row per person
|
|
10
|
+
|
|
11
|
+
The table is the app's own, keyed by the person's user id. With Better Auth the id is text, and a reference to `auth."user"` removes the row with its person. Each choice is a column with its default:
|
|
12
|
+
|
|
13
|
+
```sql title="db/migrations/021_notification_settings.sql"
|
|
14
|
+
-- Each person's choice of notification emails, one row per person, keyed by their Better Auth id. Someone who never
|
|
15
|
+
-- saved a choice has no row: read the default for them.
|
|
16
|
+
create table core.notification_settings (
|
|
17
|
+
user_id text primary key references auth."user" (id) on delete cascade,
|
|
18
|
+
overdue_invoices text not null default 'each' check (overdue_invoices in ('each', 'daily', 'never'))
|
|
19
|
+
);
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Apply it with `bun run db:migrate`. A person has no row until they first save; the default stands for them until then.
|
|
23
|
+
|
|
24
|
+
## 2. A resource each person owns
|
|
25
|
+
|
|
26
|
+
The resource names the table, its fields and their defaults, and makes the key its owner with `.owner(...)`, so each person has one record of their own. The view gives the field its label, help and the words for its values, and keeps the resource out of the sidebar:
|
|
27
|
+
|
|
28
|
+
```ts title="config/notification_settings/data.ts"
|
|
29
|
+
import { f, resource } from '@protobase/schema'
|
|
30
|
+
import { erpAccess } from '../roles'
|
|
31
|
+
|
|
32
|
+
/** core.notification_settings: each person's own, shown by the account page's Notifications tab. */
|
|
33
|
+
export const notificationSettings = resource('notification_settings')
|
|
34
|
+
.table('core.notification_settings')
|
|
35
|
+
.fields({
|
|
36
|
+
user_id: f.text(),
|
|
37
|
+
overdue_invoices: f.enum(['each', 'daily', 'never']).default('each'),
|
|
38
|
+
})
|
|
39
|
+
.primaryKey((r) => r.user_id)
|
|
40
|
+
.owner((r) => r.user_id)
|
|
41
|
+
.access(erpAccess('notification_settings'))
|
|
42
|
+
```
|
|
43
|
+
```ts title="config/notification_settings/ui.ts"
|
|
44
|
+
import { view } from '@protobase/schema'
|
|
45
|
+
import type { notificationSettings } from './data'
|
|
46
|
+
|
|
47
|
+
export const notificationSettingsView = view<typeof notificationSettings>('notification_settings')
|
|
48
|
+
.names({ singular: 'Notification setting', plural: 'Notification settings' })
|
|
49
|
+
// Each person changes their own on the account page.
|
|
50
|
+
.nav({ hidden: true })
|
|
51
|
+
.fields((r) => ({
|
|
52
|
+
overdue_invoices: r.overdue_invoices
|
|
53
|
+
.label('Overdue invoices')
|
|
54
|
+
.help('An email when an invoice passes its due date unpaid.')
|
|
55
|
+
.valueLabels({ each: 'For each invoice', daily: 'Once a day', never: 'Never' }),
|
|
56
|
+
}))
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Export both from `config/index.ts`, as every resource is.
|
|
60
|
+
|
|
61
|
+
## 3. Roles that have settings
|
|
62
|
+
|
|
63
|
+
Give each role that should have the setting `.read.own`, `.create.own` and `.update.own` on the resource, in `config/roles.ts`:
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
const ownNotificationSettings = ['notification_settings.read.own', 'notification_settings.create.own', 'notification_settings.update.own'] as const
|
|
67
|
+
|
|
68
|
+
export const roles = defineRoles<ErpName>({
|
|
69
|
+
admin: ['*'],
|
|
70
|
+
auditor: ['*.read', ...ownNotificationSettings],
|
|
71
|
+
sales: [...ownNotificationSettings, 'orders.read.own', ...],
|
|
72
|
+
// the other roles alike: manager holds them already through '*.read', '*.create' and '*.update', and the
|
|
73
|
+
// integration role, which is no person, has none
|
|
74
|
+
})
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
A role that may read but not write sees the choice without a control to change it; a role that may not read has no Notifications tab. Once a `Settings` block shows the resource, every caller reads and writes only their own record, an admin holding `*` included, in the block and in the API alike.
|
|
78
|
+
|
|
79
|
+
## 4. A tab on the account page
|
|
80
|
+
|
|
81
|
+
Export a page named `account` to replace the standard one: the standard tabs from `accountTabs`, in the order to show them, and a tab of your own with a [`Settings`](../reference/blocks.md#settings) block on the resource:
|
|
82
|
+
|
|
83
|
+
```tsx title="config/account.tsx"
|
|
84
|
+
/** @jsxImportSource @protobase/layout */
|
|
85
|
+
import { Page, Settings, Tab, Tabs, accountTabs, page } from '@protobase/layout'
|
|
86
|
+
|
|
87
|
+
/** The standard account page with a Notifications tab, where each person picks the emails they get. */
|
|
88
|
+
export const account = page(
|
|
89
|
+
'account',
|
|
90
|
+
<Page title="Account">
|
|
91
|
+
<Tabs>
|
|
92
|
+
{accountTabs.profile}
|
|
93
|
+
{accountTabs.security}
|
|
94
|
+
<Tab name="notifications" label="Notifications">
|
|
95
|
+
<Settings resource="notification_settings" title="Emails" description="What the ERP emails you about." />
|
|
96
|
+
</Tab>
|
|
97
|
+
{accountTabs.devices}
|
|
98
|
+
{accountTabs.apps}
|
|
99
|
+
</Tabs>
|
|
100
|
+
</Page>,
|
|
101
|
+
)
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Export it from `config/index.ts` too. Open **Account** in the user menu and then **Notifications**, at `/-/account/notifications`: the choice shows as a select with its label and help, set to **For each invoice** until it changes. Picking another value saves it at once; the first save creates the person's row.
|
|
105
|
+
|
|
106
|
+
## Reading the choice
|
|
107
|
+
|
|
108
|
+
Code of your own, such as a job that sends the emails, reads the choice with SQL. Someone who never saved has no row, so read the default for them:
|
|
109
|
+
|
|
110
|
+
```sql
|
|
111
|
+
select u.email
|
|
112
|
+
from auth."user" u
|
|
113
|
+
left join core.notification_settings s on s.user_id = u.id
|
|
114
|
+
where coalesce(s.overdue_invoices, 'each') = 'each'
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
The [`Settings` block](../reference/blocks.md#settings) has its props, the field types it draws and the checks it runs at startup.
|
|
@@ -26,7 +26,7 @@ defineRoles<'orders' | 'products'>({
|
|
|
26
26
|
})
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
- **Scopes**: `.own` gives the records whose [`.owner()`](data-config.md#resource) field holds the user's id, and `.team` those owned by the users that `teamOf` returns for them, a function given as `defineRoles(roles, { teamOf: (user) => ids })`. A scoped capability on a resource without `.owner()` fails the request.
|
|
29
|
+
- **Scopes**: `.own` gives the records whose [`.owner()`](data-config.md#resource) field holds the user's id, and `.team` those owned by the users that `teamOf` returns for them, a function given as `defineRoles(roles, { teamOf: (user) => ids })`. A scoped capability on a resource without `.owner()` fails the request. A resource a [`Settings`](blocks.md#settings) block shows is each person's own for every role, `*` included: its records are always limited to the caller's.
|
|
30
30
|
- **Fields** (`['sku', 'price']`, or `fields` in an object) are an allowlist: for `<resource>.read`, `.create` or `.update`, the role reads or writes only the fields listed, so a column added later stays hidden from it until someone lists it. Key columns are always there, because records are addressed by them. A plain capability (`'products.read'`) still means every field.
|
|
31
31
|
- **Filter** is AIP-160 text, like a filter an access rule returns. It narrows the rows of the capability, together with `.own` or `.team` when the capability has one.
|
|
32
32
|
- A limit names one resource, never `*`, and fields go with `read`, `create` or `update` only; `defineRoles` refuses anything else. At startup the server refuses a field the resource does not have, a filter that does not fit it, and a limit on a name that is not a resource.
|
|
@@ -137,6 +137,50 @@ New apps have it already. Leave the export out to drop it, or make a page of you
|
|
|
137
137
|
|
|
138
138
|
An invitation to the app is a row of Better Auth's `verification` table, so it needs no table of its own. The client has these as `session.users`.
|
|
139
139
|
|
|
140
|
+
## Account page
|
|
141
|
+
|
|
142
|
+
Everyone signed in has an account page at `/-/account`, which "Account" in the user menu opens. When the config exports no page named `account`, the server serves the standard one, `accountPage` from `@protobase/layout`: a [composed page](layouts.md) titled "Account" with four [tabs](blocks.md#tabs-and-tab) of [account blocks](blocks.md#account-blocks), each tab at its own address.
|
|
143
|
+
|
|
144
|
+
| Tab | Address | Blocks |
|
|
145
|
+
| --- | --- | --- |
|
|
146
|
+
| Profile | `/-/account` | `Profile` |
|
|
147
|
+
| Sign-in & security | `/-/account/security` | `Password`, `Passkeys`, `TwoFactor`, `ConnectedAccounts` |
|
|
148
|
+
| Devices | `/-/account/devices` | `Devices` |
|
|
149
|
+
| Connected apps | `/-/account/apps` | `ConnectedApps` |
|
|
150
|
+
|
|
151
|
+
A tab whose blocks all leave themselves out is not offered, such as Connected apps in an app without [MCP](#oauth-for-mcp-clients).
|
|
152
|
+
|
|
153
|
+
To change it, export a page named `account` of your own: it replaces the standard one at `/-/account`, and is neither at `/account` nor in the sidebar. `accountTabs` holds the standard tabs by name (`profile`, `security`, `devices`, `apps`), so the page lists the ones it keeps beside its own:
|
|
154
|
+
|
|
155
|
+
```tsx
|
|
156
|
+
// config/account.tsx
|
|
157
|
+
import { accountTabs, Card, page, Page, Passkeys, Tab, Tabs, TwoFactor } from '@protobase/layout'
|
|
158
|
+
|
|
159
|
+
export const account = page('account',
|
|
160
|
+
<Page title="Account">
|
|
161
|
+
<Tabs>
|
|
162
|
+
<Tab name="security" label="Sign-in & security">
|
|
163
|
+
<Card title="Company policy">Staff sign in with a passkey.</Card>
|
|
164
|
+
<Passkeys />
|
|
165
|
+
<TwoFactor />
|
|
166
|
+
</Tab>
|
|
167
|
+
{accountTabs.profile}
|
|
168
|
+
<Tab name="privacy" label="Privacy">
|
|
169
|
+
<Card title="Analytics">We count visits without cookies.</Card>
|
|
170
|
+
</Tab>
|
|
171
|
+
</Tabs>
|
|
172
|
+
</Page>)
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
- **Add** a tab of your own, here Privacy at `/-/account/privacy`, with any blocks a page can hold.
|
|
176
|
+
- **Hide** a tab by leaving it out, here Devices and Connected apps, or a block by leaving it out of its tab, here `ConnectedAccounts`.
|
|
177
|
+
- **Reorder** by listing the tabs in the order to show them: Sign-in & security comes first here, at `/-/account`.
|
|
178
|
+
- **Wrap** a standard tab by writing it with its name and label, the standard blocks among your own, as the security tab above does with a note.
|
|
179
|
+
|
|
180
|
+
A tab of personal settings, such as which emails someone gets, is a [`Settings`](blocks.md#settings) block over a resource with one record per person: the fields come from the resource, and each person reads and changes only their own.
|
|
181
|
+
|
|
182
|
+
The page is checked like any other, and the account blocks are allowed on it alone. A config that [extends](cli.md#extending-a-config) another and exports `account` too is the error of a page defined twice.
|
|
183
|
+
|
|
140
184
|
## Password reset
|
|
141
185
|
|
|
142
186
|
With mail configured, the sign-in page offers "Forgot password?": the person enters their email, gets a link, and chooses a new password on the page the link opens. It is Better Auth's own reset: `POST /api/auth/request-password-reset` with `{ email, redirectTo }`, the emailed link `GET /api/auth/reset-password/<token>`, which sends the browser back to `redirectTo` with `?token=...` (or `?error=INVALID_TOKEN`), and `POST /api/auth/reset-password` with `{ token, newPassword }`.
|
|
@@ -171,11 +215,30 @@ The signed-in person changes their own name and password, and signs out their ot
|
|
|
171
215
|
| --- | --- |
|
|
172
216
|
| `updateName(name)` | `POST /api/auth/update-user` with `{ name }` |
|
|
173
217
|
| `changePassword(current, next, signOutOthers)` | `POST /api/auth/change-password` with `{ currentPassword, newPassword, revokeOtherSessions }`, for an account that has a password (a wrong one is `INVALID_PASSWORD`) |
|
|
218
|
+
| `setPassword(next)` | `POST /api/auth/account/set-password` with `{ newPassword }`, for an account without a password, such as one that signs in with [emailed codes](#emailed-sign-in-codes) or [GitHub](#sign-in-with-github); one that has a password already is `PASSWORD_ALREADY_SET` |
|
|
174
219
|
| `sessions()` | `GET /api/auth/list-sessions`: the devices signed in now, each `{ token, current, userAgent?, ipAddress?, createdAt, updatedAt, expiresAt, staff? }`, with `current` for this one and `staff` for a [staff session](#staff-sign-in) |
|
|
175
220
|
| `revokeSession(token)` | `POST /api/auth/revoke-session` with `{ token }`: signs out that device |
|
|
176
221
|
| `revokeOtherSessions()` | `POST /api/auth/revoke-other-sessions`: signs out every device but this one |
|
|
177
222
|
|
|
178
|
-
Signing out a device, or a new password with `signOutOthers`, stops that device's API token at its next request (see [When a token stops working](#when-a-token-stops-working)); this device stays signed in. A [staff session](#staff-sign-in) cannot change the password or sign out the other devices (`STAFF_CANNOT_CHANGE_SIGN_IN`).
|
|
223
|
+
Signing out a device, or a new password with `signOutOthers`, stops that device's API token at its next request (see [When a token stops working](#when-a-token-stops-working)); this device stays signed in. A first password with `setPassword` signs out no device and disconnects no [MCP client](#oauth-for-mcp-clients); it needs 12 characters like any other, is limited to 5 per minute and client, and is refused while the [sign-in policy](#sign-in-policy) turns passwords off (`403`). A [staff session](#staff-sign-in) cannot change or set the password or sign out the other devices (`STAFF_CANNOT_CHANGE_SIGN_IN`).
|
|
224
|
+
|
|
225
|
+
On the [account page](#account-page), the `Password` block does both: with a password, it asks for the current one, the new one twice, and whether to sign out the other devices; without one, it sets the first, and nobody is signed out. While the sign-in policy turns passwords off, or in a staff session, it only says so.
|
|
226
|
+
|
|
227
|
+
The [account page](#account-page)'s Devices tab lists the sessions with this one first and marked, a Sign out on each other one and Sign out of all other devices. It names each by its browser and system from the user agent, and a staff session by the operator alone, such as "Protobase staff" with when it signed in and until when, never the staff member.
|
|
228
|
+
|
|
229
|
+
## Changing the address
|
|
230
|
+
|
|
231
|
+
With mail configured, the account page's Profile tab offers "Change email": the person enters the new address, gets a 6-digit code there, and enters it. Only then does the account move to the new address, which counts as verified; they sign in with it from then on, and this device stays signed in. It is Better Auth's [email OTP](https://www.better-auth.com/docs/plugins/email-otp) plugin's address change, and `GET /api/auth/status` says `"changeEmail": true` while it is offered. The client has it in `session.account`:
|
|
232
|
+
|
|
233
|
+
| Client | Endpoint |
|
|
234
|
+
| --- | --- |
|
|
235
|
+
| `requestEmailChange(newEmail)` | `POST /api/auth/email-otp/request-email-change` with `{ newEmail }`: mails the code to the new address |
|
|
236
|
+
| `changeEmail(newEmail, code)` | `POST /api/auth/email-otp/change-email` with `{ newEmail, otp }`: moves the account once the code is right (a wrong one is `INVALID_OTP`, an old one `OTP_EXPIRED`) |
|
|
237
|
+
|
|
238
|
+
- A code works for 5 minutes, once, and three wrong tries end it. Codes are stored hashed.
|
|
239
|
+
- An address another account has gets no code, and the answer is the same, so it does not tell who has an account.
|
|
240
|
+
- Each endpoint is limited to 3 requests per minute and client. Without mail both answer `404`.
|
|
241
|
+
- A [staff session](#staff-sign-in) cannot change the address (`STAFF_CANNOT_CHANGE_SIGN_IN`), and neither can an [MCP client](#oauth-for-mcp-clients)'s token (`401`).
|
|
179
242
|
|
|
180
243
|
## Emailed sign-in codes
|
|
181
244
|
|
|
@@ -183,7 +246,7 @@ With mail configured, the sign-in page offers "Email me a sign-in code": the per
|
|
|
183
246
|
|
|
184
247
|
- A code works for 5 minutes, once, and three wrong tries end it; asking again sends a new one and the old one stops working. Codes are stored hashed.
|
|
185
248
|
- It never creates an account: an address no account uses gets no code but an email saying so, which suggests signing in with the address the person signed up with. The answer is the same either way, so it does not tell who has an account.
|
|
186
|
-
- Only sign-in codes are mailed. The plugin's own email verification
|
|
249
|
+
- Only sign-in codes are mailed this way. The plugin's own email verification and password reset endpoints are off (`404`), and asking for another type of code answers `400`. Its address change is on, as [Changing the address](#changing-the-address) describes.
|
|
187
250
|
- An account with [two-factor authentication](#two-factor-authentication) is asked for its second step after the code too, as after a password.
|
|
188
251
|
- An account created by Protobase 0.3 or earlier, which has a password, is marked verified the first time it uses a code. Otherwise Better Auth would treat the code as taking over an unverified account and delete its password.
|
|
189
252
|
|
|
@@ -332,7 +395,7 @@ createAuth({ ..., socialProviders: { github: { clientId: process.env.GITHUB_CLIE
|
|
|
332
395
|
These work for every provider, the project's own and the [platform's](#platform-sign-in-provider):
|
|
333
396
|
|
|
334
397
|
- **Sign-in links:** `https://<app>/?sign-in=github` starts signing in with `github` at once, showing only "Signing in with GitHub" while the browser leaves, so someone the provider knows lands signed in without a sign-in page. A refusal comes back to the sign-in page with the reason (`?error=<code>`, for example `signup_disabled`), and does not start again. Someone signed in already just opens the app.
|
|
335
|
-
- **Connected accounts:** the **Sign-in & security**
|
|
398
|
+
- **Connected accounts:** the [account page](#account-page)'s **Sign-in & security** tab lists the providers and offers "Connect GitHub" for one the account is not linked to. Connecting signs in at the provider and links that account whatever its address (`accountLinking.allowDifferentEmails`, which applies only to this explicit link by someone signed in). A provider account linked to another person already is refused (`account_already_linked_to_different_user`); a [staff session](#staff-sign-in) cannot link.
|
|
336
399
|
- **Linked up front:** `protobase users create <email> --github-id <id>`, or `createUser(auth, { ..., accounts: [{ providerId: 'github', accountId }] })`, links a new user to a GitHub user id, so GitHub finds them by it whatever address it reports.
|
|
337
400
|
- Without a link, a provider finds someone by address only when it vouches for the address (`email_verified`) and the account's address is verified; accounts created by an admin or on the host are.
|
|
338
401
|
|
|
@@ -350,7 +413,7 @@ Instead of the metadata XML, `idp` takes the provider's entity ID, sign-in URL a
|
|
|
350
413
|
|
|
351
414
|
- **What the provider's admin needs:** the entity ID and metadata URL `<BETTER_AUTH_URL>/api/auth/sso/saml2/sp/metadata?providerId=okta`, which most providers import, and the ACS URL `<origin>/api/auth/sso/saml2/sp/acs/okta` for each of the app's [origins](#several-origins). The assertion carries the address as attribute `email` (or the NameID), and the name as `givenName` and `surname` or as `displayName`; `attributes: { email, name, firstName, lastName }` names other attributes. The NameID identifies the account, so a stable one is best: persistent, or the address.
|
|
352
415
|
- **Who gets in:** someone at one of `domains` (subdomains count) signs in to the account with that address, linked on the first sign-in, or gets a new one with the [default role](#roles), as with GitHub; without a default role the sign-up is refused. An address outside `domains` is refused, whether or not an account has it (`EMAIL_DOMAIN_NOT_ALLOWED`, or `account_not_linked` for an existing account). With [organizations](#organizations), people still join one by invitation.
|
|
353
|
-
- **Sign-in links** work as for the other providers: `https://<app>/?sign-in=okta` starts it at once. A SAML provider links an account by signing in, so the
|
|
416
|
+
- **Sign-in links** work as for the other providers: `https://<app>/?sign-in=okta` starts it at once. A SAML provider links an account by signing in, so the account page does not offer to connect it.
|
|
354
417
|
- `GET /api/auth/status` lists the providers as `samlProviders: [{ id, name }]`. Like `socialProviders`, they have no row in the [sign-in policy](#sign-in-policy), and a required passkey or two-factor authentication still holds back the token until it is set up.
|
|
355
418
|
- **No migration:** the providers live in config, so the store gets no table for them.
|
|
356
419
|
- The plugin's defaults stay: the response must answer a request this app made, within 5 minutes of clock skew, once. Not supported yet:
|
|
@@ -415,7 +478,7 @@ PROTOBASE_SIGN_IN_ISSUER=https://dex.example.com PROTOBASE_SIGN_IN_CLIENT_ID=erp
|
|
|
415
478
|
PROTOBASE_SIGN_IN_ISSUER=https://keycloak.example.com/realms/acme PROTOBASE_SIGN_IN_CLIENT_ID=erp PROTOBASE_SIGN_IN_CLIENT_SECRET=... PROTOBASE_SIGN_IN_NAME="Acme SSO"
|
|
416
479
|
```
|
|
417
480
|
|
|
418
|
-
People sign in with the address their account here has, or connect the provider on the Sign-in & security
|
|
481
|
+
People sign in with the address their account here has, or connect the provider on the account page's Sign-in & security tab once.
|
|
419
482
|
|
|
420
483
|
## Roles
|
|
421
484
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
Every built-in layout block, its props and what it does, with examples from the ERP's sales overview.
|
|
6
6
|
|
|
7
|
-
Blocks are imported from `@protobase/layout`. "Record" below means the record of the `RecordCard` or `CardRow` card around a block (see [Data](layouts.md#data)); `filter` is AIP-160 and `sort` AIP-132, as in the list API. Every block below but `RecordRow`, which the property portal's home uses, `RecordCards`, and `Users`, which the [Users page](auth.md#users-page) uses, appears in the ERP example's sales overview:
|
|
7
|
+
Blocks are imported from `@protobase/layout`. "Record" below means the record of the `RecordCard` or `CardRow` card around a block (see [Data](layouts.md#data)); `filter` is AIP-160 and `sort` AIP-132, as in the list API. Every block below but `RecordRow`, which the property portal's home uses, `RecordCards`, `Tabs` and `Tab`, `Settings`, and `Users`, which the [Users page](auth.md#users-page) uses, appears in the ERP example's sales overview:
|
|
8
8
|
|
|
9
9
|
```tsx title="examples/erp/config/overview/page.tsx"
|
|
10
10
|
/** @jsxImportSource @protobase/layout */
|
|
@@ -146,6 +146,30 @@ A link in text: `to` an address in the app, or an `href` that leaves it (`https:
|
|
|
146
146
|
|
|
147
147
|
One of the two is required. A link to a resource or field the user cannot see is left out of their page.
|
|
148
148
|
|
|
149
|
+
### Tabs and Tab
|
|
150
|
+
|
|
151
|
+
`Tabs` splits a page into tabs, each at its own address: the first at the page's (`/<page>`), each other at its name below it (`/<page>/<name>`). Only the shown tab's elements are drawn, so the others load nothing. On a phone the tabs are a select. `Tabs` takes no props and holds only `Tab`s; it sits directly in the `Page`, once per page, with other elements before or after it if you like.
|
|
152
|
+
|
|
153
|
+
| `Tab` prop | |
|
|
154
|
+
| --- | --- |
|
|
155
|
+
| `name` | The tab's address, after the page's, and how a [link](layouts.md#addresses) opens it (`{ kind: 'page', page, tab }`). Lowercase first letter, then letters, digits and dashes; one per tab. Required. |
|
|
156
|
+
| `label` | The tab's word in the row of tabs, and before the page's title in the browser tab. Required. |
|
|
157
|
+
|
|
158
|
+
```tsx
|
|
159
|
+
<Page title="Settings">
|
|
160
|
+
<Tabs>
|
|
161
|
+
<Tab name="general" label="General">
|
|
162
|
+
<Card title="Opening hours">Monday to Friday, 8:00 to 17:30.</Card>
|
|
163
|
+
</Tab>
|
|
164
|
+
<Tab name="billing" label="Billing">
|
|
165
|
+
<Table title="Invoices" resource="invoices" />
|
|
166
|
+
</Tab>
|
|
167
|
+
</Tabs>
|
|
168
|
+
</Page>
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
A tab whose every element a user may not see is left out of their page, and so are tabs left with none. An address with a tab name the page has no tab for (or not for this user) shows the tabs and says so.
|
|
172
|
+
|
|
149
173
|
## Data
|
|
150
174
|
|
|
151
175
|
### Stat
|
|
@@ -363,3 +387,78 @@ Everyone who can sign in, for admins: find them by address, tick their roles, bl
|
|
|
363
387
|
<Users />
|
|
364
388
|
</Page>
|
|
365
389
|
```
|
|
390
|
+
|
|
391
|
+
### Account blocks
|
|
392
|
+
|
|
393
|
+
`Profile`, `Password`, `Passkeys`, `TwoFactor`, `ConnectedAccounts`, `Devices` and `ConnectedApps` are the parts of the signed-in person's own account: their name and address (which they can change, the address with an [emailed code](auth.md#changing-the-address)), their [password](auth.md#name-password-and-devices) (changed, or set for the first time), their [passkeys](auth.md#passkeys), [two-factor authentication](auth.md#two-factor-authentication), the sign-in providers they linked, the devices signed in as them (each one but this one to [sign out](auth.md#name-password-and-devices)), and the apps such as MCP clients they allowed to act as them. Each takes no props or children, reads its own data, and leaves itself out where it does not apply: `ConnectedAccounts` without an OAuth sign-in provider, `ConnectedApps` without MCP. They act on whoever is signed in, so they are allowed on the page named `account` alone; anywhere else stops the config. That page is the [account page](auth.md#account-page) at `/-/account`, which `accountTabs` helps build from the standard tabs.
|
|
394
|
+
|
|
395
|
+
```tsx
|
|
396
|
+
export const account = page('account',
|
|
397
|
+
<Page title="Account">
|
|
398
|
+
<Profile />
|
|
399
|
+
<Passkeys />
|
|
400
|
+
<TwoFactor />
|
|
401
|
+
</Page>)
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
### Settings
|
|
405
|
+
|
|
406
|
+
The signed-in person's own record of `resource` as settings, one field under the other with its label and help: a switch for a boolean, a select for an enum, an input for the other types. A switch or a select saves as soon as it changes; typed values save with **Save**, or Enter. Until the person saves for the first time there is no record, and each field shows its `.default(...)`; the first save creates the record, owned by them, and later saves update it with its ETag. Errors from the server show on their fields.
|
|
407
|
+
|
|
408
|
+
| Prop | |
|
|
409
|
+
| --- | --- |
|
|
410
|
+
| `resource` | A resource whose `.owner(...)` field is its key, so each person has one record. Required. |
|
|
411
|
+
| `fields` | The fields it shows; default every field a person can set: not the key, read-only, sensitive or file fields. |
|
|
412
|
+
| `title`, `description` | Its heading. |
|
|
413
|
+
| `span` | As for `Card`. |
|
|
414
|
+
|
|
415
|
+
**Each person's own, admins too.** Every caller of the API, an admin holding `*` included, reads and writes only the records of the resource they own, wherever they ask: the block, the resource's list and record pages, exports, the API and API functions. A caller without a token gets nothing of it. Only SQL of your own and the built-in assistant's [SQL tools](assistant.md#the-built-in-backend), which run outside the access rules for every resource, read every row. The roles still decide who has settings at all: give each role that should `<resource>.read.own`, `.create.own` and `.update.own`. Someone who may read but not write sees the values, not controls; someone who may not read gets no block, and a field they may not read is left out.
|
|
416
|
+
|
|
417
|
+
The startup check stops the config when the resource has no `.owner(...)`, when its owner is not its whole key, when it has a [tenant](data-config.md#resource) (settings are each person's own, not an organization's), when it has no field a person can set, and when `fields` names an unknown, key, sensitive or file field.
|
|
418
|
+
|
|
419
|
+
A person's notification choices, in a tab of the [account page](auth.md#account-page); the guide [Add a personal setting](../guides/personal-setting.md) walks through the ERP example's. The table has one row per person, keyed by their user id, which is text with Better Auth:
|
|
420
|
+
|
|
421
|
+
```sql
|
|
422
|
+
-- db/migrations/012_preferences.sql
|
|
423
|
+
create table preferences (
|
|
424
|
+
user_id text primary key,
|
|
425
|
+
digest text not null default 'weekly' check (digest in ('daily', 'weekly', 'never')),
|
|
426
|
+
mentions boolean not null default true
|
|
427
|
+
);
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
```ts
|
|
431
|
+
// config/preferences/data.ts
|
|
432
|
+
export const preferences = resource('preferences')
|
|
433
|
+
.table('preferences')
|
|
434
|
+
.fields({ user_id: f.text(), digest: f.enum(['daily', 'weekly', 'never']).default('weekly'), mentions: f.boolean().default(true) })
|
|
435
|
+
.primaryKey((r) => r.user_id)
|
|
436
|
+
.owner((r) => r.user_id)
|
|
437
|
+
|
|
438
|
+
// config/preferences/ui.ts: labels, help and the values' words, and no sidebar entry
|
|
439
|
+
export const preferencesView = view<typeof preferences>('preferences')
|
|
440
|
+
.nav({ hidden: true })
|
|
441
|
+
.fields((r) => ({
|
|
442
|
+
digest: r.digest.label('Email digest').help('A summary of what changed in your orders.').valueLabels({ daily: 'Every day', weekly: 'Every week', never: 'Never' }),
|
|
443
|
+
mentions: r.mentions.label('Email me when someone mentions me'),
|
|
444
|
+
}))
|
|
445
|
+
|
|
446
|
+
// roles: everyone who signs in has their own
|
|
447
|
+
member: ['preferences.read.own', 'preferences.create.own', 'preferences.update.own', ...]
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
```tsx
|
|
451
|
+
// config/account.tsx
|
|
452
|
+
export const account = page('account',
|
|
453
|
+
<Page title="Account">
|
|
454
|
+
<Tabs>
|
|
455
|
+
{accountTabs.profile}
|
|
456
|
+
{accountTabs.security}
|
|
457
|
+
<Tab name="notifications" label="Notifications">
|
|
458
|
+
<Settings resource="preferences" title="Notifications" description="What we email you about." />
|
|
459
|
+
</Tab>
|
|
460
|
+
</Tabs>
|
|
461
|
+
</Page>)
|
|
462
|
+
```
|
|
463
|
+
|
|
464
|
+
Other code reads the choices with SQL, such as a job that sends the digest: `select user_id from preferences where digest = 'daily'`. Someone who never saved has no row, so it reads the default for them: `coalesce(digest, 'weekly')` over a left join from the users.
|
|
@@ -23,7 +23,7 @@ With an absolute `baseUrl`, such as another app's `https://desk.example.com/api/
|
|
|
23
23
|
|
|
24
24
|
## The admin app
|
|
25
25
|
|
|
26
|
-
`<App baseUrl="/api/v1" />` renders the shell from `/api/meta` (beside the API, so `createClient` derives it from `baseUrl`) and routes `/:page` ([composed pages](layouts.md)), `/:resource` (list) and `/:resource/:key` (record); it opens on the first entry of the [sidebar](sidebar.md) the user sees, or, with none, the first page or resource. Its own pages sit under `/-/`, which no page or resource name takes: `/-/account` (the user's
|
|
26
|
+
`<App baseUrl="/api/v1" />` renders the shell from `/api/meta` (beside the API, so `createClient` derives it from `baseUrl`) and routes `/:page` and `/:page/:tab` ([composed pages](layouts.md) and their [tabs](blocks.md#tabs-and-tab)), `/:resource` (list) and `/:resource/:key` (record); it opens on the first entry of the [sidebar](sidebar.md) the user sees, or, with none, the first page or resource. Its own pages sit under `/-/`, which no page or resource name takes: `/-/account` and its tabs (the user's [account page](auth.md#account-page), from `/meta`'s `account`) and `/-/sign-in-policy` (admins: the policy, and the log of staff sign-ins). Before the shell, it signs in on its sign-in route, `/-/sign-in`, with the methods the server offers and asks for what the [sign-in policy](auth.md#sign-in-policy) requires. Someone signed out goes there from any page, with that page in `?next=`, and signing in comes back to it; each step (a forgotten password, an emailed code, making an account) adds `?step=`, so the browser's Back returns to the step before; `?staff-sign-in` opens the [staff sign-in](auth.md#staff-sign-in) page instead, and a staff session gets a banner below the top bar. `createAuthSession` from `@protobase/client` is that session (`signIn`, `signInWithCode`, `signInWithPasskey`, `verifyTwoFactor`, `account`, `signInPolicy`, `staff`). `ui` takes the project's [custom components and action handlers](custom-components.md). The list state lives in the URL: `?list=`, a [named list](ui-config.md#more-than-one-list), `?filter=` (AIP-160), `?order_by=`, `?display=`, the [display](ui-config.md#list-displays) it shows, `?layout=panel`, the filters in a panel beside the table on a desktop instead of a bar above it, `?map=52.37,4.89,12`, where a [map](ui-config.md#maps) looks, `?calendar=month,2026-10-01`, the month or week a [calendar](ui-config.md#calendars) shows, `?timeline=quarter,2026-10-01`, the week, month or quarter a [timeline](ui-config.md#timelines) shows, and `?saved_search=`, the [saved search](ui-config.md#saved-searches) the list was opened from. Views come from `examples/*/config/*/ui.ts`. The sidebar's recent-record groups and the user menu are configured there too: see [Sidebar](sidebar.md), [User menu](user-menu.md) and [Bottom bar](bottom-bar.md).
|
|
27
27
|
|
|
28
28
|
## Global search
|
|
29
29
|
|
|
@@ -107,7 +107,7 @@ Every place in the app has an address, and the app writes and reads them in one
|
|
|
107
107
|
| `{ kind: 'list', resource, filter?, orderBy?, display? }` | A resource's list, with the filter, order and [display](ui-config.md#list-displays) the list page would show. |
|
|
108
108
|
| `{ kind: 'record', resource, key, edit?, open?, tab? }` | One record; `key` is its value, or its parts for a composite key. `edit: true` is its form (`?edit=true`), on a view whose record page opens as a [read view or locked](ui-config.md#read-view-and-edit). `open` lists the titles of the record page's collapsed [groups](ui-config.md#groups) that are open (`?open=<title>`, once per group), and `tab` the title of the [tab](ui-config.md#tabs) it shows (`?tab=<title>`). |
|
|
109
109
|
| `{ kind: 'create', resource, values? }` | The form for a new record, with `values` filled in by field name, as text: `{ kind: 'create', resource: 'notes', values: { listing_id: '{id}' } }` on a listing's page starts a note about that listing. A relation shows the name of the record it points at. The values are a start the person can change, not a rule: what they may write is still up to the access rules. A view with a [create page](ui-config.md#create-pages) shows that page here instead, with the values in the address. |
|
|
110
|
-
| `{ kind: 'page', page }` | A composed page. |
|
|
110
|
+
| `{ kind: 'page', page, tab? }` | A composed page; `tab` the name of one of its [tabs](blocks.md#tabs-and-tab) (`/<page>/<tab>`), the first when omitted. |
|
|
111
111
|
|
|
112
112
|
The resources, pages and fields an address names are checked when the server starts, like every other name.
|
|
113
113
|
|
|
@@ -118,7 +118,7 @@ Every block reads the regular API with the user's token, so the access rules app
|
|
|
118
118
|
`/api/meta` also gives each user the page without what they cannot use, the way views lose hidden fields:
|
|
119
119
|
|
|
120
120
|
- a page whose `roles` leave the user out is not sent;
|
|
121
|
-
- an element whose resource they cannot see, or whose filter or sort names a field they cannot read, is left out with everything inside it;
|
|
121
|
+
- an element whose resource they cannot see, or whose filter or sort names a field they cannot read, is left out with everything inside it, and so is a `Tab` left with nothing in it;
|
|
122
122
|
- `Field`, `Progress` and `Stat field` on a field they cannot read are left out, and table columns are narrowed;
|
|
123
123
|
- `ModalForm` needs create or update permission and keeps only the fields they may write;
|
|
124
124
|
- an `Action` missing from their view of the resource is left out, and so is a `Show` that names something they cannot see.
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
The user menu at the bottom of the sidebar, with the app's own account pages and links.
|
|
6
6
|
|
|
7
|
-
The signed-in user sits at the bottom of the sidebar. Clicking them opens a menu with their name and email, the app's own pages, the theme switch, and "Sign out". Account pages (organization, billing, users) and help links belong here rather than among the working resources.
|
|
7
|
+
The signed-in user sits at the bottom of the sidebar. Clicking them opens a menu with their name and email, which link to their account, the app's own pages, the theme switch, and "Sign out". Account pages (organization, billing, users) and help links belong here rather than among the working resources.
|
|
8
8
|
|
|
9
9
|
Export one [`userMenu(...)`](https://docs.protobase.net/api/schema/functions/usermenu/) from the config module:
|
|
10
10
|
|
|
@@ -26,7 +26,7 @@ export const accountMenu = userMenu((m) => [
|
|
|
26
26
|
| `m.page(name, { label?, icon? })` | Opens a [composed page](layouts.md). The page leaves the sidebar. The label defaults to its title. |
|
|
27
27
|
| `m.link(label, href, { icon? })` | Opens `href` in a new tab. Only `https://`, `http://` and `mailto:` are accepted. |
|
|
28
28
|
|
|
29
|
-
`accounts` is the built-in [Users page](auth.md#users-page), which the config exports as `usersPage` from `@protobase/layout`; without the export, `createAdmin` refuses the item. Items keep their order.
|
|
29
|
+
`accounts` is the built-in [Users page](auth.md#users-page), which the config exports as `usersPage` from `@protobase/layout`; without the export, `createAdmin` refuses the item. Items keep their order. A line splits the menu into groups: these items, then the [organization](auth.md#organizations) pages when the app has organizations, then the person's own: "Account" for everyone (their [account page](auth.md#account-page): profile, [passkeys](auth.md#passkeys) and [two-factor authentication](auth.md#two-factor-authentication)) and "Sign-in policy" for admins (the [sign-in policy](auth.md#sign-in-policy), and the log of [staff sign-ins](auth.md#staff-sign-in)); then the [theme switch](theme.md#light-dark-or-the-system), and "Sign out" always comes last. `icon` is one of `bell`, `book-open`, `bookmark`, `building`, `credit-card`, `external-link`, `file-text`, `heart`, `key`, `layout-dashboard`, `life-buoy`, `mail`, `receipt`, `settings`, `shield`, `users`. A resource item without one uses the resource's sidebar icon, and a link item uses `external-link`.
|
|
30
30
|
|
|
31
31
|
Every caller gets the menu through `/meta`, without the resources and pages they cannot see, so a user who cannot read `organizations` has no "Organization" item. Links are shown to everyone. `createAdmin` refuses to start when an item names a resource or page that does not exist, and `configExports` refuses a config module that exports two menus.
|
|
32
32
|
|