@protobase/cli 0.40.7 → 0.40.9
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/references/getting-started.md +8 -8
- package/skills/protobase/references/guides/api-functions.md +12 -12
- package/skills/protobase/references/guides/billing-page.md +2 -2
- package/skills/protobase/references/guides/create-page.md +5 -5
- package/skills/protobase/references/guides/deploy.md +6 -6
- package/skills/protobase/references/guides/export-a-list.md +2 -2
- package/skills/protobase/references/guides/field-type.md +2 -2
- package/skills/protobase/references/guides/first-composed-page.md +4 -4
- package/skills/protobase/references/guides/first-plugin.md +3 -3
- package/skills/protobase/references/guides/import-records.md +1 -1
- package/skills/protobase/references/guides/mobile-app.md +11 -4
- package/skills/protobase/references/guides/plugin-build.md +5 -5
- package/skills/protobase/references/guides/record-card.md +3 -3
- package/skills/protobase/references/guides/remote-resources.md +10 -10
- package/skills/protobase/references/guides/table-to-admin.md +5 -5
- package/skills/protobase/references/guides/theme-an-app.md +4 -4
- package/skills/protobase/references/reference/access.md +9 -9
- package/skills/protobase/references/reference/ai.md +6 -6
- package/skills/protobase/references/reference/api.md +25 -25
- package/skills/protobase/references/reference/app-identity.md +4 -4
- package/skills/protobase/references/reference/architecture.md +1 -1
- package/skills/protobase/references/reference/assistant.md +6 -6
- package/skills/protobase/references/reference/auth.md +20 -20
- package/skills/protobase/references/reference/blocks.md +18 -13
- package/skills/protobase/references/reference/bottom-bar.md +5 -5
- package/skills/protobase/references/reference/cli.md +63 -63
- package/skills/protobase/references/reference/client.md +5 -5
- package/skills/protobase/references/reference/comments.md +8 -8
- package/skills/protobase/references/reference/custom-components.md +18 -18
- package/skills/protobase/references/reference/data-config.md +26 -26
- package/skills/protobase/references/reference/email.md +8 -8
- package/skills/protobase/references/reference/events.md +5 -5
- package/skills/protobase/references/reference/files.md +7 -7
- package/skills/protobase/references/reference/forms.md +6 -6
- package/skills/protobase/references/reference/history.md +7 -7
- package/skills/protobase/references/reference/installable-app.md +1 -1
- package/skills/protobase/references/reference/jobs.md +5 -5
- package/skills/protobase/references/reference/layouts.md +11 -11
- package/skills/protobase/references/reference/live.md +4 -4
- package/skills/protobase/references/reference/mcp.md +5 -5
- package/skills/protobase/references/reference/plugins.md +20 -20
- package/skills/protobase/references/reference/remote-resources.md +15 -15
- package/skills/protobase/references/reference/sidebar.md +1 -1
- package/skills/protobase/references/reference/supabase-realtime.md +2 -2
- package/skills/protobase/references/reference/supabase-rest.md +2 -2
- package/skills/protobase/references/reference/supabase-storage.md +1 -1
- package/skills/protobase/references/reference/theme.md +5 -5
- package/skills/protobase/references/reference/ui-config.md +60 -60
- package/skills/protobase/references/reference/user-menu.md +3 -3
- package/skills/protobase/references/reference/versioning.md +5 -5
- package/skills/protobase/references/reference/webhooks.md +7 -7
|
@@ -35,7 +35,7 @@ bun run protobase auth migration # compares it with what Better Auth needs; w
|
|
|
35
35
|
bun run db:migrate # applies it
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
The file only adds tables, columns and indexes, never drops one except the OAuth tables of [MCP](#oauth-for-mcp-clients) once `mcp` is off, and is plain SQL to review, edit or leave out where the project handles the auth schema itself. `--dir` and `--name` choose the folder and the name after the number. [`protobase migration`](cli.md#migration)
|
|
38
|
+
The file only adds tables, columns and indexes, never drops one except the OAuth tables of [MCP](#oauth-for-mcp-clients) once `mcp` is off, and is plain SQL to review, edit or leave out where the project handles the auth schema itself. `--dir` and `--name` choose the folder and the name after the number. [`protobase migration`](cli.md#migration) writes the same file, along with what the config's other features need, such as [jobs](jobs.md).
|
|
39
39
|
|
|
40
40
|
The store's tables and columns are snake_case, like the app's (`sign_in_policy.platform_sign_in`, `session.user_id`); the code and the API keep Better Auth's camelCase names. A store set up by Protobase 0.6 has Better Auth's camelCase names instead (`"signInPolicy"."platformSignIn"`): for it, `protobase auth migration` writes the migration that renames its tables, columns, indexes and constraints in place, keeping every row. The examples carry it as `db/migrations/*_auth_snake_case.sql`; on a store with the snake_case names it does nothing.
|
|
41
41
|
|
|
@@ -64,7 +64,7 @@ createAuth({
|
|
|
64
64
|
- `passwordHashes: ['bcrypt']` also verifies bcrypt hashes (`$2a$`, `$2b$`, `$2y$`), and stores the password again as Better Auth's own scrypt after its first sign-in. The 12-character minimum holds for new passwords only, so a shorter existing one still signs in.
|
|
65
65
|
- `generateUserId: 'uuid'` makes each new user's id a random UUID in the server, for a table whose `id` is a `uuid` without a default, and makes every id column of the other tables a `uuid` too.
|
|
66
66
|
|
|
67
|
-
The columns Better Auth needs that the table lacks come first, from a migration of the project's own; `protobase auth migration` then writes the other tables next to it, and another migration fills the columns from what the other system recorded and gives each password its `credential` row in `account`. For Supabase, [`protobase import supabase`](cli.md#import-supabase)
|
|
67
|
+
The columns Better Auth needs that the table lacks come first, from a migration of the project's own; `protobase auth migration` then writes the other tables next to it, and another migration fills the columns from what the other system recorded and gives each password its `credential` row in `account`. For Supabase, [`protobase import supabase`](cli.md#import-supabase) writes all three and these options.
|
|
68
68
|
|
|
69
69
|
## Configuration
|
|
70
70
|
|
|
@@ -75,24 +75,24 @@ The columns Better Auth needs that the table lacks come first, from a migration
|
|
|
75
75
|
| `TRUSTED_ORIGINS` | extra comma separated origins; a dev tunnel needs its exact host here, such as `https://my-tunnel.trycloudflare.com`, since no wildcard is trusted |
|
|
76
76
|
| `PROTOBASE_ORIGINS` | the other origins the app is served on, comma separated, passed by the platform; see [Several origins](#several-origins) |
|
|
77
77
|
| `PROTOBASE_PASSKEY_DOMAIN` | the host new [passkeys](#passkeys) are made for, passed by the platform; default the host of `BETTER_AUTH_URL` |
|
|
78
|
-
| `PROTOBASE_CORS_ORIGINS` | other websites whose browser code may call the API, `*` or comma separated http and https origins, passed by the platform; see [CORS](api.md#cors)
|
|
78
|
+
| `PROTOBASE_CORS_ORIGINS` | other websites whose browser code may call the API, `*` or comma separated http and https origins, passed by the platform; see [CORS](api.md#cors) |
|
|
79
79
|
| `PROTOBASE_SMTP_URL`, `PROTOBASE_MAIL_FROM` | the mail server and sender for [password reset](#password-reset), [emailed sign-in codes](#emailed-sign-in-codes), emailed [two-factor](#two-factor-authentication) codes and [open sign-up](#open-sign-up), passed by the platform; all four are off without them |
|
|
80
80
|
| `PROTOBASE_APP_NAME` | the app's name, passed by the platform: it overrides `appName` |
|
|
81
81
|
| `PROTOBASE_SIGN_IN_ISSUER`, `PROTOBASE_SIGN_IN_CLIENT_ID`, `PROTOBASE_SIGN_IN_CLIENT_SECRET` | the [platform sign-in provider](#platform-sign-in-provider) for people who have an account, passed by the platform; off without them. `PROTOBASE_SIGN_IN_PROVIDER` and `PROTOBASE_SIGN_IN_NAME` are optional |
|
|
82
82
|
| `PROTOBASE_OPERATOR_ISSUER`, `PROTOBASE_OPERATOR_CLIENT_ID`, `PROTOBASE_OPERATOR_CLIENT_SECRET` | the [operator provider](#operator-provider) its staff sign in with to sign in as people, passed by the platform; staff sign-in is off without them. `PROTOBASE_OPERATOR_NAME` and `PROTOBASE_OPERATOR_GROUP` are optional |
|
|
83
|
-
| `PROTOBASE_TRUSTED_PROXIES` | the proxies in front of `protobase serve`, addresses or CIDR ranges, comma separated, such as `172.30.87.1`, the Docker network's gateway in the [compose template](../guides/deploy.md#compose-template)
|
|
83
|
+
| `PROTOBASE_TRUSTED_PROXIES` | the proxies in front of `protobase serve`, addresses or CIDR ranges, comma separated, such as `172.30.87.1`, the Docker network's gateway in the [compose template](../guides/deploy.md#compose-template); see [Client addresses](#client-addresses) |
|
|
84
84
|
|
|
85
85
|
- Cookies are `SameSite=Lax`, and `Secure` when `BETTER_AUTH_URL` is https.
|
|
86
86
|
- Sign-in is rate limited (5 password attempts per minute and client by default, `signInPerMinute`, which also limits [sign-up](#open-sign-up) requests; 3 per minute for emailed codes); [Client addresses](#client-addresses) says how a client is known.
|
|
87
87
|
- New passwords need at least 12 characters.
|
|
88
|
-
- `appName` is the app's name: authenticator apps and passkey prompts show it, the admin app's sidebar shows it at the top beside the app's [icon](app-identity.md#the-icons)
|
|
88
|
+
- `appName` is the app's name: authenticator apps and passkey prompts show it, the admin app's sidebar shows it at the top beside the app's [icon](app-identity.md#the-icons), else Protobase's mark (Protobase's wordmark when it is `Protobase`), every browser tab of the admin app ends its title with it, the [installed app](installable-app.md) is called by it, the [auth emails](email.md#protobases-own-mail) name the app with it, and the platform's mailer sends them as it (the sender's display name). `PROTOBASE_APP_NAME`, when set, overrides it; without either it is `Protobase`, then without a display name. See [App identity](app-identity.md).
|
|
89
89
|
|
|
90
90
|
### Client addresses
|
|
91
91
|
|
|
92
92
|
The rate limits count each client address on its own: an IPv4 address, or an IPv6 address by its /64. `protobase serve` and the runtime image find it themselves and pass it on in `X-Forwarded-For`, replacing whatever the client sent:
|
|
93
93
|
|
|
94
94
|
- Without `PROTOBASE_TRUSTED_PROXIES`, the client is the address the connection comes from. That fits clients that reach the server directly, such as a browser on the same machine as `docker run -p 127.0.0.1:8787:8787`.
|
|
95
|
-
- Behind a reverse proxy (Caddy, nginx, Traefik, a load balancer), every connection comes from the proxy, so every client would share its one limit, and three emailed codes a minute from anyone would stop everyone signing in. Set `PROTOBASE_TRUSTED_PROXIES` to the proxy's address, or the Docker network's gateway for a proxy on the host, such as `172.30.87.1` in the deploy guide's [compose template](../guides/deploy.md#compose-template)
|
|
95
|
+
- Behind a reverse proxy (Caddy, nginx, Traefik, a load balancer), every connection comes from the proxy, so every client would share its one limit, and three emailed codes a minute from anyone would stop everyone signing in. Set `PROTOBASE_TRUSTED_PROXIES` to the proxy's address, or the Docker network's gateway for a proxy on the host, such as `172.30.87.1` in the deploy guide's [compose template](../guides/deploy.md#compose-template); a range must not cover the clients themselves, or they all share the one limit again. Have the proxy append the address it took the request from to `X-Forwarded-For` (Caddy and Traefik do by default, nginx with `proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for`). The client is then the rightmost address in it that is not a trusted proxy, so one the client wrote itself counts for nothing. Behind several proxies, such as a CDN in front of Caddy, trust them all.
|
|
96
96
|
|
|
97
97
|
An app served another way than `protobase serve`, such as its own server around `createAdmin`, gets what its server passes: the limits read `X-Forwarded-For` holding one address, and requests without one share a single limit.
|
|
98
98
|
|
|
@@ -117,7 +117,7 @@ Until a user exists sign-in fails, and `GET /api/auth/status` (public) answers `
|
|
|
117
117
|
|
|
118
118
|
## Users page
|
|
119
119
|
|
|
120
|
-
Admins manage accounts without the command line on the Users page, an ordinary [composed page](layouts.md)
|
|
120
|
+
Admins manage accounts without the command line on the Users page, an ordinary [composed page](layouts.md) the config imports: everyone who can sign in, found by address, with their roles to tick, Block and Unblock, inviting someone by email, and adding an account directly.
|
|
121
121
|
|
|
122
122
|
```ts
|
|
123
123
|
// config/index.ts
|
|
@@ -126,7 +126,7 @@ export { usersPage } from '@protobase/layout' // at /accounts, for admins
|
|
|
126
126
|
export const accountMenu = userMenu((m) => [m.page('accounts', { label: 'Users', icon: 'users' })])
|
|
127
127
|
```
|
|
128
128
|
|
|
129
|
-
New apps have it already. Leave the export out to drop it, or make a page of your own around the [`Users` block](blocks.md#users)
|
|
129
|
+
New apps have it already. Leave the export out to drop it, or make a page of your own around the [`Users` block](blocks.md#users). It works with or without [organizations](#organizations): an invitation to the app makes an account with the roles the admin ticked, from the same link page and sign-up as an organization's invitation, and someone with an account just signs in. Listing, creating, roles and blocking are Better Auth's admin endpoints (`/api/auth/admin/list-users`, `create-user`, `set-role`, `ban-user`, `unban-user`), whose roles go as a list; the rest are Protobase's, for admins only:
|
|
130
130
|
|
|
131
131
|
| Endpoint | Does |
|
|
132
132
|
| --- | --- |
|
|
@@ -153,9 +153,9 @@ createAuth({ ..., mailer: { send: async ({ to, subject, text }) => { /* deliver
|
|
|
153
153
|
createAuth({ ..., mailer: false })
|
|
154
154
|
```
|
|
155
155
|
|
|
156
|
-
[Jobs](jobs.md#mail)
|
|
156
|
+
[Jobs](jobs.md#mail) send their own mail through the same server, with `mail` in their context, and so do the app's [email templates](email.md).
|
|
157
157
|
|
|
158
|
-
- The email names the app and gives the link, as a button and in its plain-text part, that it works for 1 hour and once, and that it can be ignored (see [Protobase's own mail](email.md#protobases-own-mail))
|
|
158
|
+
- The email names the app and gives the link, as a button and in its plain-text part, that it works for 1 hour and once, and that it can be ignored (see [Protobase's own mail](email.md#protobases-own-mail)).
|
|
159
159
|
- The SMTP client greets the server with the sender's domain (`admin.example.com` above), not the container's `[127.0.0.1]`; a `?name=` on `PROTOBASE_SMTP_URL` overrides it.
|
|
160
160
|
- A request answers the same whether or not the address has an account, and the mail goes out after the answer, so neither the response nor its timing tells. A send that fails is logged by Better Auth.
|
|
161
161
|
- Requests are limited to 3 per minute and client. Setting a new password ends all of the user's sessions; the new password needs 12 characters like any other.
|
|
@@ -181,7 +181,7 @@ Off by default: accounts come from the host, an admin, an [invitation](#users-pa
|
|
|
181
181
|
createAuth({ ..., roles: ['admin', 'member'], signUp: { role: 'member' } })
|
|
182
182
|
```
|
|
183
183
|
|
|
184
|
-
The sign-in page then offers "Create an account", and so do [sign-in prompts](ui-config.md#sign-in-prompts)
|
|
184
|
+
The sign-in page then offers "Create an account", and so do [sign-in prompts](ui-config.md#sign-in-prompts): the person enters their address, gets a 6-digit code, and enters it on a page of its own. Only once the code is right does the next page ask for their name and a password. The account is made only then, with the address verified, and signed in.
|
|
185
185
|
|
|
186
186
|
- `role` is one of `roles`, and never `admin`: `createAuth` stops with an error otherwise. Give it the least a stranger may hold; a request that names another role, or sets `role` through Better Auth's own endpoints, does not get it.
|
|
187
187
|
- It needs mail: without a mailer it is not offered, `GET /api/auth/status` has no `signUp`, and its endpoints answer `404`. Not with [organizations](#organizations), whose people join by invitation.
|
|
@@ -402,7 +402,7 @@ People sign in with the address their account here has, or connect the provider
|
|
|
402
402
|
|
|
403
403
|
The roles are a project setting: `createAuth({ ..., roles: ['admin', 'auditor', 'sales', 'accountant'] })`. `admin` is always included and first; the default is `['admin', 'user']`. Names are lowercase letters, digits, `_` and `-`. `defaultRole` is what a new user gets when no role is given. Without it, and with more than one role besides `admin`, creating a user without a role is an error that lists the choices (the CLI then needs `--role`); with exactly one other role, that role is the default. `auth.defaultRole` is `undefined` when a role must be chosen. A user can hold several roles (`setUserRole(auth, { email, role: 'sales,accountant' })`), and acts with one of them at a time, the [active role](#active-role).
|
|
404
404
|
|
|
405
|
-
`createUser`, `setUserRole` and Better Auth's own admin endpoints refuse a role outside the list. `roleChoices(auth)` returns the list, for the CLI's `users set-role` and for UIs. Only `admin` gains Better Auth admin-plugin permissions (managing users); every other role is for your access rules, which see them as `ctx.user.roles`. Besides `admin`, the role `ai` opens the [assistant](assistant.md#who-sees-it)
|
|
405
|
+
`createUser`, `setUserRole` and Better Auth's own admin endpoints refuse a role outside the list. `roleChoices(auth)` returns the list, for the CLI's `users set-role` and for UIs. Only `admin` gains Better Auth admin-plugin permissions (managing users); every other role is for your access rules, which see them as `ctx.user.roles`. Besides `admin`, the role `ai` opens the [assistant](assistant.md#who-sees-it) when the project lists it.
|
|
406
406
|
|
|
407
407
|
### Active role
|
|
408
408
|
|
|
@@ -434,7 +434,7 @@ It is Better Auth's organization plugin, with its tables named in snake_case (`o
|
|
|
434
434
|
|
|
435
435
|
**Who gives which role.** Someone may give or take away a member's app role only if they hold it, in that organization or globally, or hold a role whose `grants` list it (`manager` above gives `accountant` without holding it); grants do not chain, and a superuser may give any. Only a superuser changes global roles. The creator of an organization becomes its owner with every app role (`creatorAppRoles`, default `'all'`), so they can give them on; for a role added later, list it in a role owners hold, or run `protobase organizations add-app-role <role> --to owners`.
|
|
436
436
|
|
|
437
|
-
**The organization in the token.** A new session starts in the organization the person last worked in, else their oldest membership. `/api/auth/token` adds `org` (the organization), `org_role` and `app_roles` (the membership's, narrowed to the active role), read when the token is issued; a removed member's token, or one carrying an app role taken away, [stops working](#when-a-token-stops-working) on its next request. `betterAuthAuthenticator` makes `org` the tenant and `ctx.organization.id`, and adds `app_roles` to the global roles. `POST /api/auth/organization/switch` with `{ organizationId }` moves the session; the next token names the new organization, without signing in again. Someone with a global role may switch into any organization, without being a member, and sees there what those roles allow; each such entry is an `organization.entered` [audit event](api.md#audit-events)
|
|
437
|
+
**The organization in the token.** A new session starts in the organization the person last worked in, else their oldest membership. `/api/auth/token` adds `org` (the organization), `org_role` and `app_roles` (the membership's, narrowed to the active role), read when the token is issued; a removed member's token, or one carrying an app role taken away, [stops working](#when-a-token-stops-working) on its next request. `betterAuthAuthenticator` makes `org` the tenant and `ctx.organization.id`, and adds `app_roles` to the global roles. `POST /api/auth/organization/switch` with `{ organizationId }` moves the session; the next token names the new organization, without signing in again. Someone with a global role may switch into any organization, without being a member, and sees there what those roles allow; each such entry is an `organization.entered` [audit event](api.md#audit-events). `GET /api/auth/organization/search?query=&offset=` lists every organization for them, ordered by slug, 20 at a time with the `total`, narrowed by text in the name or slug; the Organizations page shows it as All organizations. A list across organizations stays a resource without `.tenant`, readable by the global role.
|
|
438
438
|
|
|
439
439
|
**Invitations.** Better Auth's `POST /api/auth/organization/invite-member` with `{ organizationId, email, role, appRoles }`; inviting again replaces the earlier invitation, and it works for `invitationDays` (default 7). The email links to `{baseURL}/-/invitation?token=…` (`invitationUrl`), with a token signed with `secret`, since members can read invitation ids; without a mailer, the answer carries the `link` to pass on. The link page shows `GET /api/auth/invitation?token=`, accepts with `POST /api/auth/invitation/accept` for someone signed in as the invited address, and makes an account with `POST /api/auth/invitation/sign-up` (`{ token, name, password? }`) for an address without one. The link page and its sign-up serve [invitations to the app](#users-page) too. [Open sign-up](#open-sign-up) is not available with organizations: an invitation is the address someone vouched for.
|
|
440
440
|
|
|
@@ -452,7 +452,7 @@ Sign in at `POST /api/auth/sign-in/email` (or with a code or passkey), then `GET
|
|
|
452
452
|
|
|
453
453
|
`betterAuthAuthenticator` maps the claims to a session: `sub` is the user id, `roles` come from the `role` claim, the session's [active role](#active-role) of those in the admin plugin's `role` column on the user (a comma separated string; the first user is always `admin`). Access rules see them as `ctx.user.roles`. Without organizations, the tenant is the configured `tenant` option, never a claim; with them, it is the organization the session works in (`org`, see [organizations](#organizations)). The key set is cached in memory: read once, again every 10 minutes (so removed keys stop being accepted), and again when a token names an unknown `kid` (a rotated key), at most once per 30 seconds however many such tokens arrive (`cache: { refreshMs, minReloadMs }`). Pass `jwksUrl` and `issuer` instead of `auth` when the API runs apart from the auth server.
|
|
454
454
|
|
|
455
|
-
`jwtAuthenticator` accepts asymmetric signature algorithms only unless you pass `algorithms` explicitly (the tests do, for HS256), so a token cannot be forged with a public key used as an HMAC secret; Better Auth signs with its own key pair and publishes the public keys at `/api/auth/jwks`. An expired, tampered, wrongly signed or missing token is a `401` problem with `WWW-Authenticate: Bearer`; with an [anonymous role](access.md#anonymous-access)
|
|
455
|
+
`jwtAuthenticator` accepts asymmetric signature algorithms only unless you pass `algorithms` explicitly (the tests do, for HS256), so a token cannot be forged with a public key used as an HMAC secret; Better Auth signs with its own key pair and publishes the public keys at `/api/auth/jwks`. An expired, tampered, wrongly signed or missing token is a `401` problem with `WWW-Authenticate: Bearer`; with an [anonymous role](access.md#anonymous-access), a missing one on the resources API is served as that role instead.
|
|
456
456
|
|
|
457
457
|
### When a token stops working
|
|
458
458
|
|
|
@@ -472,13 +472,13 @@ The cost is two or three lookups by key in the auth store per request: the sessi
|
|
|
472
472
|
|
|
473
473
|
## Users of another app
|
|
474
474
|
|
|
475
|
-
An API can admit the signed-in users of another Protobase app with the tokens that app issues, so that app's admin app can draw its resources as [remote resources](remote-resources.md)
|
|
475
|
+
An API can admit the signed-in users of another Protobase app with the tokens that app issues, so that app's admin app can draw its resources as [remote resources](remote-resources.md). `betterAuthAuthenticator`'s `apps` lists each such app by its `baseURL`, the issuer of its tokens, with the roles its users' global roles become here:
|
|
476
476
|
|
|
477
477
|
```ts
|
|
478
478
|
betterAuthAuthenticator({ auth, apps: [{ issuer: 'https://shop.example.com', roles: { admin: 'shop' }, tenant: 1 }] })
|
|
479
479
|
```
|
|
480
480
|
|
|
481
|
-
Their tokens are verified against that app's keys at `<issuer>/api/auth/jwks`; a role it does not map is dropped, a role held in one of its organizations never counts, and a user left with none gets `403`; their id here is `<sub>@<that app's host>`. See [Signing in at the source](remote-resources.md#signing-in-at-the-source)
|
|
481
|
+
Their tokens are verified against that app's keys at `<issuer>/api/auth/jwks`; a role it does not map is dropped, a role held in one of its organizations never counts, and a user left with none gets `403`; their id here is `<sub>@<that app's host>`. See [Signing in at the source](remote-resources.md#signing-in-at-the-source).
|
|
482
482
|
|
|
483
483
|
## supabase-js and @supabase/ssr
|
|
484
484
|
|
|
@@ -509,7 +509,7 @@ It is signed with the same keys and carries the same claims as a token from `/ap
|
|
|
509
509
|
|
|
510
510
|
## OAuth for MCP clients
|
|
511
511
|
|
|
512
|
-
With `mcp`, the app is an OAuth provider for MCP clients, such as AI assistants and code editors that speak MCP: a person adds the app's MCP address to the client, the client registers itself, the person signs in on the app's own pages and allows it on the connect page, and the client gets tokens that act as that person. What the client can do with them is in [MCP](mcp.md)
|
|
512
|
+
With `mcp`, the app is an OAuth provider for MCP clients, such as AI assistants and code editors that speak MCP: a person adds the app's MCP address to the client, the client registers itself, the person signs in on the app's own pages and allows it on the connect page, and the client gets tokens that act as that person. What the client can do with them is in [MCP](mcp.md).
|
|
513
513
|
|
|
514
514
|
```ts
|
|
515
515
|
createAuth({ ..., mcp: true })
|
|
@@ -540,14 +540,14 @@ createAuth({ ..., baseURL: 'https://erp-x1.protobase.net', origins: ['https://ad
|
|
|
540
540
|
- Sessions are cookies of each host: a person signs in once per origin.
|
|
541
541
|
- `GET /.well-known/webauthn` answers `{ "origins": [...] }` with every origin of the app, on each of them, so its [passkeys](#passkeys) work on all. `protobase serve` and `protobase dev` send that path to the server, whatever the bundle's `api` says; a host in front must too.
|
|
542
542
|
- Each origin is a URL with the scheme of `baseURL`; one that is not stops the server at startup. The host that serves the app must pass each origin's own `Host` header on.
|
|
543
|
-
- The app's own origins may call each other's API from the browser ([CORS](api.md#cors))
|
|
543
|
+
- The app's own origins may call each other's API from the browser ([CORS](api.md#cors)).
|
|
544
544
|
|
|
545
545
|
## Public endpoints
|
|
546
546
|
|
|
547
|
-
Only the Better Auth routes under `/api/auth/*` (sign-in, password reset, [open sign-up](#open-sign-up), the start and callback of a [staff sign-in](#staff-sign-in), and with [MCP](#oauth-for-mcp-clients) the OAuth provider's register, token and authorize, and the like), `GET /api/auth/status`, with MCP the two OAuth discovery documents under `/.well-known/`, and, with [several origins](#several-origins), `GET /.well-known/webauthn` are reachable without a token; the account, policy and staff session endpoints there need a session. The API (`/api/v1/*`) and the system endpoints (`/api/meta`, `/api/openapi.json`, `/api/docs`) all answer `401` without one, but for what an [anonymous role](access.md#anonymous-access)
|
|
547
|
+
Only the Better Auth routes under `/api/auth/*` (sign-in, password reset, [open sign-up](#open-sign-up), the start and callback of a [staff sign-in](#staff-sign-in), and with [MCP](#oauth-for-mcp-clients) the OAuth provider's register, token and authorize, and the like), `GET /api/auth/status`, with MCP the two OAuth discovery documents under `/.well-known/`, and, with [several origins](#several-origins), `GET /.well-known/webauthn` are reachable without a token; the account, policy and staff session endpoints there need a session. The API (`/api/v1/*`) and the system endpoints (`/api/meta`, `/api/openapi.json`, `/api/docs`) all answer `401` without one, but for what an [anonymous role](access.md#anonymous-access) reads in `/api/v1` and `/api/meta`, when the project defines one. [Public forms](forms.md#routes) (`/api/forms/*`) need no token either.
|
|
548
548
|
|
|
549
549
|
## Roles and access in the API
|
|
550
550
|
|
|
551
|
-
Roles are bundles of capabilities (`defineRoles` in `@protobase/schema`: `orders.read.own`, `costs.read`, `*.read`, ...). Pass the result as `options.roles` to `createAdmin`, and every operation without an explicit rule needs the matching capability; a capability may be limited to [fields and rows](access.md#capabilities)
|
|
551
|
+
Roles are bundles of capabilities (`defineRoles` in `@protobase/schema`: `orders.read.own`, `costs.read`, `*.read`, ...). Pass the result as `options.roles` to `createAdmin`, and every operation without an explicit rule needs the matching capability; a capability may be limited to [fields and rows](access.md#capabilities). The token's `roles` become `ctx.user.roles` in rules; the user id (`sub`) is what `.own` compares with the resource's `.owner(...)` field, so it must be the id that field stores. How the API enforces them (hidden fields, row filters, record permissions) is in [the REST API reference](api.md#access).
|
|
552
552
|
|
|
553
553
|
**User ids.** Better Auth gives a new user a random 32-character text id, so an `.owner(...)` field holds `text`: the server refuses to start (`protobase dev`, `serve`) when one holds integers or UUIDs, naming the field. An app whose owner columns are integers, such as a relation to its own users table, gives `createAuth` a `generateUserId` that takes the next value of that table's sequence, and adds the user's row there, as the ERP example does (`examples/erp/auth/auth.ts`, with the row added by `db/migrations/019_auth_users.sql` when someone joins an organization). One whose owner columns are UUIDs gives it `generateUserId: 'uuid'` (see [An existing users table](#an-existing-users-table)). An authenticator that maps the signed-in account to a user of the app's own, such as a wrapper around `betterAuthAuthenticator` that returns the id of a row in its users table, declares the type of those ids instead, `Object.assign(authenticate, { userIdType: 'uuid' })` (or `'integer'`, `'bigint'`, `'text'`), and the owner fields are checked against that. A request by a user whose id the owner field cannot hold, such as one made before `generateUserId`, fails with an `owner-id-mismatch` problem that names the field.
|
|
@@ -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))
|
|
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:
|
|
8
8
|
|
|
9
9
|
```tsx title="examples/erp/config/overview/page.tsx"
|
|
10
10
|
/** @jsxImportSource @protobase/layout */
|
|
@@ -141,7 +141,7 @@ A link in text: `to` an address in the app, or an `href` that leaves it (`https:
|
|
|
141
141
|
|
|
142
142
|
| Prop | |
|
|
143
143
|
| --- | --- |
|
|
144
|
-
| `to` | An [address](layouts.md#addresses)
|
|
144
|
+
| `to` | An [address](layouts.md#addresses). Inside a record, `{field}` in its key, filter or order is the record's value. |
|
|
145
145
|
| `href` | A link that leaves the app. A path in the app is refused when the config loads: give it as `to`. |
|
|
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.
|
|
@@ -158,7 +158,7 @@ One number or value with a label. Exactly one of `value`, `resource` and `field`
|
|
|
158
158
|
| `value` | A fixed value. |
|
|
159
159
|
| `resource`, `filter` | Counts the matching records the user can see; the card links to that filtered list. |
|
|
160
160
|
| `field` | A field of the record, through relations (`plan.name`). |
|
|
161
|
-
| `format` | Instead of the view's [format](ui-config.md#names-and-columns)
|
|
161
|
+
| `format` | Instead of the view's [format](ui-config.md#names-and-columns), such as `badge`. |
|
|
162
162
|
| `description` | A line under the value. |
|
|
163
163
|
| `span` | Width in a grid. |
|
|
164
164
|
|
|
@@ -168,7 +168,7 @@ One number or value with a label. Exactly one of `value`, `resource` and `field`
|
|
|
168
168
|
|
|
169
169
|
### Table
|
|
170
170
|
|
|
171
|
-
The first records of a list, drawn the way the resource's list page draws them: its table, or one of the view's [list displays](ui-config.md#list-displays)
|
|
171
|
+
The first records of a list, drawn the way the resource's list page draws them: its table, or one of the view's [list displays](ui-config.md#list-displays) such as cards, with the same switch between them when the view has several. A row or card opens the record, and **View all** opens the list with the same filter and order. On a phone a view with a cards display opens in it, as one row of cards that scrolls sideways; a display the viewer picks is kept for them in the browser.
|
|
172
172
|
|
|
173
173
|
| Prop | |
|
|
174
174
|
| --- | --- |
|
|
@@ -217,9 +217,9 @@ Up to `limit` records side by side, each a small card made from the children, wh
|
|
|
217
217
|
|
|
218
218
|
### RecordRow
|
|
219
219
|
|
|
220
|
-
What a filter finds, the way a home page shows it: the filter's chips, as the list's filter panel names them, how many records match, the records as the cards of the resource's [cards display](ui-config.md#list-displays)
|
|
220
|
+
What a filter finds, the way a home page shows it: the filter's chips, as the list's filter panel names them, how many records match, the records as the cards of the resource's [cards display](ui-config.md#list-displays) in one row, and **View all**, which opens the list with the same filter and order. The row scrolls sideways by touch, trackpad or its arrow buttons; only the cards near the view are drawn, and the records load through the list API in pages as it scrolls. Each card opens its record. A resource without a cards display gets cards of the title alone.
|
|
221
221
|
|
|
222
|
-
It follows the resource's view as its list page does. Of a resource whose view has [`listOf`](ui-config.md#favorites)
|
|
222
|
+
It follows the resource's view as its list page does. Of a resource whose view has [`listOf`](ui-config.md#favorites), such as favorites, it shows the records the user's saved ones point at, as their own resource's cards, and **View all** opens the favorites. Of one whose view has [`searchesOf`](ui-config.md#saved-searches), it shows a row for each of the user's saved searches, under its name or its filters, with the records new to them marked **New** and **View all results**, as their list page shows them. `filter` and `sort` do not apply to those two.
|
|
223
223
|
|
|
224
224
|
| Prop | |
|
|
225
225
|
| --- | --- |
|
|
@@ -236,11 +236,15 @@ It follows the resource's view as its list page does. Of a resource whose view h
|
|
|
236
236
|
|
|
237
237
|
### RecordCards
|
|
238
238
|
|
|
239
|
-
What a filter finds as the cards of a record page's [related records as cards](ui-config.md#related-records-as-cards)
|
|
239
|
+
What a filter finds as the cards of a record page's [related records as cards](ui-config.md#related-records-as-cards), stacked full width under a heading that has no card around it, so the page shows no card inside another: each record's title linking to its page, its `fields` under their labels, a value taller than a few lines cut short with **Show more**, and a button for each of `cardActions`, run as on the record page. Below the cards, **View all** opens the list with the same filter and order, beside a note such as "The first 10 of 37." when there are more.
|
|
240
|
+
|
|
241
|
+
With `layout="carousel"` the cards sit side by side in one row that scrolls sideways, by touch, trackpad, mouse wheel or its scrollbar, and snaps each card to its left edge. Each card is `cardWidth` of the block's width, so the next one peeks in, but never narrower than 12rem, so narrow cards stay readable on a phone. The cards are top aligned and keep their fields and buttons.
|
|
240
242
|
|
|
241
243
|
| Prop | |
|
|
242
244
|
| --- | --- |
|
|
243
245
|
| `resource`, `filter`, `sort` | Which records, in which order. `resource` is required; `sort` defaults to the list's. |
|
|
246
|
+
| `layout` | `stack` (default) or `carousel`. |
|
|
247
|
+
| `cardWidth` | In a carousel, the width of each card as a share of the block's: `1/4`, `1/3`, `1/2` or `2/3` (default). |
|
|
244
248
|
| `fields` | The fields each card shows, through relations too (`task_id.title`); default the list's columns. |
|
|
245
249
|
| `cardActions` | Named actions of the resource's view, as buttons on each card. |
|
|
246
250
|
| `limit` | How many; default 10. |
|
|
@@ -251,6 +255,7 @@ What a filter finds as the cards of a record page's [related records as cards](u
|
|
|
251
255
|
|
|
252
256
|
```tsx
|
|
253
257
|
<RecordCards title="Waiting on you" resource="task_preconditions" filter="state = 'waiting'" fields={['task_id', 'plan']} cardActions={['approve', 'request_changes']} />
|
|
258
|
+
<RecordCards title="Runners" resource="runners" layout="carousel" cardWidth="1/4" fields={['state']} />
|
|
254
259
|
```
|
|
255
260
|
|
|
256
261
|
### Field
|
|
@@ -261,7 +266,7 @@ A label over a value of the record, formatted as on the record page: statuses as
|
|
|
261
266
|
| --- | --- |
|
|
262
267
|
| `name` | A field, through relations (`company_id.city`). Required. |
|
|
263
268
|
| `label` | Default: the view's label, else the name in words. `false` shows the value alone. |
|
|
264
|
-
| `format` | Instead of the view's [format](ui-config.md#names-and-columns)
|
|
269
|
+
| `format` | Instead of the view's [format](ui-config.md#names-and-columns). |
|
|
265
270
|
|
|
266
271
|
### Progress
|
|
267
272
|
|
|
@@ -279,7 +284,7 @@ A bar for `value` out of `max`, with both numbers. It turns amber from 90%.
|
|
|
279
284
|
|
|
280
285
|
### Chart
|
|
281
286
|
|
|
282
|
-
Counts, sums or averages of the records that match `filter`, per value of a field or per hour, day, week, month or year of a date field, in a card. It reads [`:aggregate`](api.md#routes)
|
|
287
|
+
Counts, sums or averages of the records that match `filter`, per value of a field or per hour, day, week, month or year of a date field, in a card. It reads [`:aggregate`](api.md#routes), so only what the user may see is counted, and the grouped field needs an index ([scan guard](api.md#safety)).
|
|
283
288
|
|
|
284
289
|
| Prop | |
|
|
285
290
|
| --- | --- |
|
|
@@ -299,13 +304,13 @@ Counts, sums or averages of the records that match `filter`, per value of a fiel
|
|
|
299
304
|
<Chart title="Revenue per day by status" resource="orders" groupBy="created_at" splitBy="status" sum="total" />
|
|
300
305
|
```
|
|
301
306
|
|
|
302
|
-
Each value takes its colour from the view's `valueColors`, else an enum value's place among its values, from the [chart tokens](theme.md#tokens)
|
|
307
|
+
Each value takes its colour from the view's `valueColors`, else an enum value's place among its values, from the [chart tokens](theme.md#tokens). A chart whose field the user cannot read is left out of their page, and a field it cannot group or add up stops the server at startup.
|
|
303
308
|
|
|
304
309
|
## Behaviour
|
|
305
310
|
|
|
306
311
|
### Action
|
|
307
312
|
|
|
308
|
-
A button for a [named action](layouts.md#named-actions)
|
|
313
|
+
A button for a [named action](layouts.md#named-actions) of the view, on the record around it.
|
|
309
314
|
|
|
310
315
|
| Prop | |
|
|
311
316
|
| --- | --- |
|
|
@@ -335,7 +340,7 @@ A button that opens a form in a dialog. `create` makes a record of `resource`; `
|
|
|
335
340
|
|
|
336
341
|
### Show
|
|
337
342
|
|
|
338
|
-
Its children while [`when`](layouts.md#conditions)
|
|
343
|
+
Its children while [`when`](layouts.md#conditions) holds.
|
|
339
344
|
|
|
340
345
|
| Prop | |
|
|
341
346
|
| --- | --- |
|
|
@@ -351,7 +356,7 @@ Its children while [`when`](layouts.md#conditions)) holds.
|
|
|
351
356
|
|
|
352
357
|
### Users
|
|
353
358
|
|
|
354
|
-
Everyone who can sign in, for admins: find them by address, tick their roles, block or unblock them, invite someone by email and add an account. It takes no props or children. The [Users page](auth.md#users-page)
|
|
359
|
+
Everyone who can sign in, for admins: find them by address, tick their roles, block or unblock them, invite someone by email and add an account. It takes no props or children. The [Users page](auth.md#users-page) is a `Page` with it alone; a page of your own can put it beside other blocks, with `roles: ['admin']`, since the server refuses everyone else.
|
|
355
360
|
|
|
356
361
|
```tsx
|
|
357
362
|
<Page title="People">
|
|
@@ -6,7 +6,7 @@ Tabs along the bottom of a phone, as on iOS, for the roles that work from one.
|
|
|
6
6
|
|
|
7
7
|
On phones the sidebar is a drawer behind the top bar's menu button. For people who work from a phone, such as on a warehouse floor, a bottom bar puts their few screens one tap away: up to four tabs, each an icon above its label, the current one highlighted, and "More" last, which opens the drawer with the rest. The bar keeps clear of the iPhone home indicator. From the `md` breakpoint (768px) up there is no bar; the sidebar shows instead.
|
|
8
8
|
|
|
9
|
-
Export a [`bottomBar(...)`](https://docs.protobase.net/api/schema/functions/bottombar/)
|
|
9
|
+
Export a [`bottomBar(...)`](https://docs.protobase.net/api/schema/functions/bottombar/) from the config module for each group of roles that gets one:
|
|
10
10
|
|
|
11
11
|
```ts
|
|
12
12
|
// examples/erp/config/bottom-bar.ts, re-exported from config/index.ts
|
|
@@ -23,18 +23,18 @@ export const warehouseBar = bottomBar({ label: 'Warehouse', roles: ['warehouse']
|
|
|
23
23
|
| Item | Does |
|
|
24
24
|
| --- | --- |
|
|
25
25
|
| `m.resource(name, { label, icon? })` | Opens the resource's list. Without `icon`, the resource's sidebar icon. |
|
|
26
|
-
| `m.page(name, { label, icon? })` | Opens a [composed page](layouts.md)
|
|
26
|
+
| `m.page(name, { label, icon? })` | Opens a [composed page](layouts.md). Without `icon`, the page's own. |
|
|
27
27
|
| `m.link(label, href, { icon? })` | Opens `href` in a new tab. Only `https://`, `http://` and `mailto:` are accepted. |
|
|
28
28
|
|
|
29
|
-
Every tab needs its `label`: tabs are narrow, so the bar does not borrow a view's or page's longer name. `icon` takes the names the [user menu](user-menu.md)
|
|
29
|
+
Every tab needs its `label`: tabs are narrow, so the bar does not borrow a view's or page's longer name. `icon` takes the names the [user menu](user-menu.md) does. Items keep their order. Unlike the user menu, a bar takes nothing out of the sidebar.
|
|
30
30
|
|
|
31
31
|
## Which bar someone gets
|
|
32
32
|
|
|
33
|
-
Each bar names its roles, and a role belongs to one bar. A caller gets the bar that names their active role, through `/meta` as `bottomBar`, without the resources and pages they cannot see, except that a visitor keeps a resource whose view has a [sign-in prompt](ui-config.md#sign-in-prompts)
|
|
33
|
+
Each bar names its roles, and a role belongs to one bar. A caller gets the bar that names their active role, through `/meta` as `bottomBar`, without the resources and pages they cannot see, except that a visitor keeps a resource whose view has a [sign-in prompt](ui-config.md#sign-in-prompts), which tells them to sign in; a bar with none left is not sent. Someone whose active role no bar names gets no bar. The active role is the one the session acts with, which the person [switches in the profile menu](auth.md#active-role); with an authenticator other than Better Auth's, the caller's first role.
|
|
34
34
|
|
|
35
35
|
## Checks
|
|
36
36
|
|
|
37
|
-
`createAdmin` refuses to start when a bar names a resource or page that does not exist, has no roles, no items or more than four, names a role the app does not have (the roles of [`createAuth`](auth.md)
|
|
37
|
+
`createAdmin` refuses to start when a bar names a resource or page that does not exist, has no roles, no items or more than four, names a role the app does not have (the roles of [`createAuth`](auth.md) and [`defineRoles`](access.md); without either, any role is accepted), shares a role with another bar, or has the label of another bar. The checks are [`bottomBarErrors`](https://docs.protobase.net/api/schema/functions/bottombarerrors/) from `@protobase/schema`, a pure function of the bars and the app's names.
|
|
38
38
|
|
|
39
39
|
`protobase dev`, `protobase build` and `protobase serve` pick the bars up from the config module. With `createAdmin` directly, pass them as `bottomBars`:
|
|
40
40
|
|