@protobase/cli 0.84.0 → 0.85.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/package.js +1 -1
- package/package.json +8 -8
- package/skills/protobase/SKILL.md +1 -0
- package/skills/protobase/references/features/sign-in-and-accounts.md +3 -2
- package/skills/protobase/references/reference/api.md +1 -1
- package/skills/protobase/references/reference/auth.md +10 -8
- package/skills/protobase/references/reference/blocks.md +1 -1
- package/skills/protobase/references/reference/config/sign-in.md +11 -0
- package/skills/protobase/references/reference/personal-access-tokens.md +73 -0
package/dist/cli/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.85.1",
|
|
4
4
|
"description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -43,13 +43,13 @@
|
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@better-auth/core": "^1.7.12",
|
|
45
45
|
"@hono/node-server": "^2.1.3",
|
|
46
|
-
"@protobase/config": "0.
|
|
47
|
-
"@protobase/layout": "0.
|
|
48
|
-
"@protobase/query": "0.
|
|
49
|
-
"@protobase/schema": "0.
|
|
50
|
-
"@protobase/server": "0.
|
|
51
|
-
"@protobase/ui": "0.
|
|
52
|
-
"@protobase/workflows": "0.
|
|
46
|
+
"@protobase/config": "0.85.1",
|
|
47
|
+
"@protobase/layout": "0.85.1",
|
|
48
|
+
"@protobase/query": "0.85.1",
|
|
49
|
+
"@protobase/schema": "0.85.1",
|
|
50
|
+
"@protobase/server": "0.85.1",
|
|
51
|
+
"@protobase/ui": "0.85.1",
|
|
52
|
+
"@protobase/workflows": "0.85.1",
|
|
53
53
|
"@react-email/render": "^2.1.0",
|
|
54
54
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
55
55
|
"@sentry/vite-plugin": "^11.10.0",
|
|
@@ -97,6 +97,7 @@ Reference:
|
|
|
97
97
|
- When adding audio and video calls, through LiveKit or peer to peer → read [Calls](references/reference/calls.md)
|
|
98
98
|
- When setting roles, capabilities and row filters → read [Access](references/reference/access.md)
|
|
99
99
|
- When configuring sign-in, tokens and the auth schema → read [Login with Better Auth](references/reference/auth.md)
|
|
100
|
+
- When a script or integration calls the app's API as a person with a long-lived token, or turning `auth.personalAccessTokens` on → read [Personal access tokens](references/reference/personal-access-tokens.md)
|
|
100
101
|
- When using the typed client and hooks → read [Client and live UI](references/reference/client.md)
|
|
101
102
|
- When writing composed pages in JSX → read [Layouts](references/reference/layouts.md)
|
|
102
103
|
- When looking for a built-in layout block and its props → read [Blocks](references/reference/blocks.md)
|
|
@@ -11,7 +11,7 @@ Sign-in methods, users, roles, organizations and tokens.
|
|
|
11
11
|
- [Versioned sign-in tables](../reference/auth.md#migrations): The sign-in tables come from numbered migrations that ship with Protobase, written as the project's own and recorded in the database, so a deploy checks them without comparing tables. Every feature has its tables from the start, so turning one on or off needs no migration.
|
|
12
12
|
- [Existing users table](../reference/auth.md#an-existing-users-table): Sign-in can use the users table another system keeps in the same database.
|
|
13
13
|
- [Users page](../reference/auth.md#users-page): Admins find people, set roles, block them, add accounts and invite people by email.
|
|
14
|
-
- [Account page](../reference/auth.md#account-page): Everyone signed in has an account page for their profile, sign-in and security, devices and
|
|
14
|
+
- [Account page](../reference/auth.md#account-page): Everyone signed in has an account page for their profile, sign-in and security, devices, connected apps and access tokens, and you add, hide or reorder its tabs.
|
|
15
15
|
- [Password reset](../reference/auth.md#password-reset): People reset a forgotten password through an emailed link.
|
|
16
16
|
- [Password changes](../reference/auth.md#name-password-and-devices): Changing the password signs out every other device and MCP client, and emails the account that its password changed. Guesses at the current password are limited for each account.
|
|
17
17
|
- [Leaked passwords](../reference/auth.md#leaked-passwords): New passwords that appear in a known data breach are refused, when the app turns the check on.
|
|
@@ -22,7 +22,7 @@ Sign-in methods, users, roles, organizations and tokens.
|
|
|
22
22
|
- [Passkeys](../reference/auth.md#passkeys): People sign in with their device's face or fingerprint unlock, or with a security key.
|
|
23
23
|
- [Two-factor authentication](../reference/auth.md#two-factor-authentication): A second step with an authenticator app, backup codes or emailed codes.
|
|
24
24
|
- [Emailed confirmation code](../reference/auth.md#emailed-confirmation-code): Someone without a passkey or a second step confirms it's them with a code emailed on request, where they are, such as before a secret is shown.
|
|
25
|
-
- [Confirming an account change](../reference/auth.md#confirming-an-account-change): Adding a passkey, turning on a second step without a password, unlinking a provider or deleting the account from an older session asks to confirm it's them in place, never to sign out and sign in again; a first passkey takes the password too.
|
|
25
|
+
- [Confirming an account change](../reference/auth.md#confirming-an-account-change): Adding a passkey, turning on a second step without a password, unlinking a provider, making a personal access token or deleting the account from an older session asks to confirm it's them in place, never to sign out and sign in again; a first passkey takes the password too.
|
|
26
26
|
- [Sign-in policy](../reference/auth.md#sign-in-policy): Admins choose which sign-in methods are on, off or required, and the server refuses a policy that would lock people out.
|
|
27
27
|
- [GitHub and social sign-in](../reference/auth.md#sign-in-with-github): People sign in with GitHub or another social provider.
|
|
28
28
|
- [Sign-in links](../reference/auth.md#sign-in-links-and-connected-accounts): A link signs someone in with a sign-in provider at once, without the sign-in page.
|
|
@@ -38,5 +38,6 @@ Sign-in methods, users, roles, organizations and tokens.
|
|
|
38
38
|
- [Signing key rotation](../reference/auth.md#signing-keys): The keys that sign the tokens are replaced every 30 days on their own, and old ones keep verifying the tokens they signed for a week.
|
|
39
39
|
- [Changing the secret](../reference/auth.md#changing-the-secret): The app's secret can change while the signing keys keep signing, by listing the old secret beside the new one.
|
|
40
40
|
- [Tokens for scripts](../reference/auth.md#tokens-for-scripts-and-curl): A token for an existing user, for scripts and curl, in any organization they work in.
|
|
41
|
+
- [Personal access tokens](../reference/personal-access-tokens.md): People make long-lived tokens on their account page for a script to call the API as them, see when each was last used, and revoke any of them. The app keeps only each token's hash.
|
|
41
42
|
- [Several origins](../reference/auth.md#several-origins): One app works on several domains, such as its own address and a custom domain.
|
|
42
43
|
- [Sign-in rate limits](../reference/auth.md#client-addresses): Sign-in and code requests are limited per client address, also behind a proxy.
|
|
@@ -214,7 +214,7 @@ The rules behind these steps are described under [Access](#access).
|
|
|
214
214
|
- **Keys** are the URL text (`a,b` when composite), a number, a list of parts, or a reference.
|
|
215
215
|
- **`$ref`**: `ref: 'invoice'` on a create names the record; later operations use `{ "$ref": "invoice" }` as a key, a key part, or a value in `data` (it stands for that record's key, or with `{ "$ref": "invoice", "field": "number" }` a readable field's value). A ref must come after its create.
|
|
216
216
|
- **`reorder`** sets `field` to `start`, `start` + 1, ... in the order of `keys`, so a long list sends only the stretch that moved, and writes only the records whose value changes, each as an ordinary update (so each needs its `etags` entry, and hooks see each). To work with a non-deferrable unique index such as `(invoice_id, position)`, the changing records are first moved out of the range in use, in the same transaction and without touching their ETags: above the highest value of the column, or, when a check constraint refuses that (checked with a savepoint), below the lowest one. Then they get their final values, which collide with nothing. The field must be an integer the caller may write; the keys must all exist and be visible to the caller. When it is the resource's [position with `after`](ui-config.md#ranked-after-what-they-depend-on), a reorder that puts a record at or above a record it depends on, or one of those at or below it, fails with `409` and the type `ranks-above-dependency`, naming both keys in `record` and `dependsOn`; pairs out of order before it do not count.
|
|
217
|
-
- **`move`** puts the record `key` just after `after`, or first when it is `null`, in the list `filter` reads (as a list's `filter` does) ordered by `field`. It is anchored to that place rather than to ETags: it saves while the record after `after` there, leaving out the moved one, is still `before` (`null`: none), whatever else changed in the list or in the records, and fails with `412` otherwise, so the caller reads the list again. Leave `before` out when the caller did not load the record after `after`; then only `after` is checked. The server reads the list in its current order and renumbers the shortest stretch that saves the move, written as a `reorder` writes it, so the same field rules, unique index handling and `ranks-above-dependency` check apply. Moves and reorders of the same resource's `field` run one at a time, and a record of the stretch renumbered by another write between the move's read and its write refuses it with `412` too. A filter needs indexes as a list's does.
|
|
217
|
+
- **`move`** puts the record `key` just after `after`, or first when it is `null`, in the list `filter` reads (as a list's `filter` does) ordered by `field`. It is anchored to that place rather than to ETags: it saves while the record after `after` there, leaving out the moved one, is still `before` (`null`: none), whatever else changed in the list or in the records, and fails with `412` otherwise, so the caller reads the list again. Leave `before` out when the caller did not load the record after `after`; then only `after` is checked. The server reads the list in its current order and renumbers the shortest stretch that saves the move, written as a `reorder` writes it, so the same field rules, unique index handling and `ranks-above-dependency` check apply. Moves and reorders of the same resource's `field` run one at a time, together with the creates and updates through this API that set the resource's `.position()` field ([data config](data-config.md)), and a record of the stretch renumbered by another write between the move's read and its write refuses it with `412` too. <gap>A write of the position through the [PostgREST-compatible API](supabase-rest.md) cannot make a move wait because that API taking the order lock is not implemented.</gap> A filter needs indexes as a list's does.
|
|
218
218
|
- **Result**: `{ results: [...] }`, one entry per operation in order: `create` and `update` give `record` and `etag`, `delete` gives `deleted: true`, `reorder` gives `records` (every key in order, with its etag), and `move` the records it numbered, in order, with their etags. Each of those records comes with `previous`, its value of `field` before the operation, which an undo puts back.
|
|
219
219
|
- **Failure**: nothing is written. The problem is the failing operation's own (`400`, `403`, `404`, `409`, `412`, `428`, ...) with `operation` (its index), `op` and `resource` added. A stale ETag anywhere is a `412` for the whole batch.
|
|
220
220
|
|
|
@@ -36,7 +36,7 @@ bun run db:migrate # applies them
|
|
|
36
36
|
|
|
37
37
|
Each version's statements are followed by its row in `auth_migrations`. The file only adds tables, columns and indexes, never drops one, 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).
|
|
38
38
|
|
|
39
|
-
Every store has the tables of every feature, whether the app turns the feature on or not: [passkeys](#passkeys), [two-factor authentication](#two-factor-authentication), [organizations](#organizations)
|
|
39
|
+
Every store has the tables of every feature, whether the app turns the feature on or not: [passkeys](#passkeys), [two-factor authentication](#two-factor-authentication), [organizations](#organizations), the [OAuth provider for MCP](#oauth-for-mcp-clients) and [personal access tokens](personal-access-tokens.md). Turning a feature on or off needs no migration and drops nothing; the columns a feature adds to the user and session tables are empty until it is on. SAML providers and open sign-up keep nothing in the store.
|
|
40
40
|
|
|
41
41
|
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. The names the app configures, the store's schema ([`auth.schema`](config/sign-in.md#authschema)), the [user table](#an-existing-users-table) and its columns, and uuid ids (`generateUserId: 'uuid'`), are the ones in effect when the file is written. Changing one later is a migration of the project's own, such as a rename.
|
|
42
42
|
|
|
@@ -91,7 +91,7 @@ The store's migrations then make nothing of the user table, which a migration of
|
|
|
91
91
|
| `PROTOBASE_TRUSTED_ORIGINS` | extra comma separated origins, the default of `auth.trustedOrigins`; a dev tunnel needs its exact host here, such as `https://my-tunnel.trycloudflare.com`, since none is trusted by default; an entry with `*` trusts every host it matches |
|
|
92
92
|
| `PROTOBASE_ORIGINS` | the other origins the app is served on, comma separated, passed by the platform; see [Several origins](#several-origins) |
|
|
93
93
|
| `PROTOBASE_PASSKEY_DOMAIN` | the host new [passkeys](#passkeys) are made for, passed by the platform; default the host of the app's `url` |
|
|
94
|
-
| `PROTOBASE_LOCKED_ACCOUNTS` | the addresses of accounts no one may take over, comma separated, passed by the platform, such as a demo's shared account: their address, password, passkeys, two-factor authentication
|
|
94
|
+
| `PROTOBASE_LOCKED_ACCOUNTS` | the addresses of accounts no one may take over, comma separated, passed by the platform, such as a demo's shared account: their address, password, passkeys, two-factor authentication, linked accounts and [personal access tokens](personal-access-tokens.md) stay as they are, from any endpoint or host call, which fails with `403 ACCOUNT_LOCKED`, and they cannot be deleted |
|
|
95
95
|
| `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) |
|
|
96
96
|
| `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 |
|
|
97
97
|
| `PROTOBASE_APP_NAME` | the app's name, passed by the platform: it overrides `name` |
|
|
@@ -185,7 +185,7 @@ An invitation to the app is a row of Better Auth's `verification` table, so it n
|
|
|
185
185
|
|
|
186
186
|
## Account page
|
|
187
187
|
|
|
188
|
-
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
|
|
188
|
+
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 five [tabs](blocks.md#tabs-and-tab) of [account blocks](blocks.md#account-blocks), each tab at its own address.
|
|
189
189
|
|
|
190
190
|
| Tab | Address | Blocks |
|
|
191
191
|
| --- | --- | --- |
|
|
@@ -193,10 +193,11 @@ Everyone signed in has an account page at `/-/account`, which "Account" in the u
|
|
|
193
193
|
| Sign-in & security | `/-/account/security` | `Password`, `Passkeys`, `TwoFactor`, `ConnectedAccounts` |
|
|
194
194
|
| Devices | `/-/account/devices` | `Devices` |
|
|
195
195
|
| Connected apps | `/-/account/apps` | `ConnectedApps` |
|
|
196
|
+
| Access tokens | `/-/account/tokens` | `PersonalAccessTokens` |
|
|
196
197
|
|
|
197
|
-
A tab whose blocks all leave themselves out is not offered, such as Connected apps in an app without [MCP](#oauth-for-mcp-clients). `DeleteAccount` leaves itself out when the app turns [account deletion](#deleting-the-account) off, `PersonalMail` in an app without [personal mail](email.md#from-someones-own-mailbox), and `Connections` when no workflow plugin declares a [connection](workflows.md#connecting-an-account).
|
|
198
|
+
A tab whose blocks all leave themselves out is not offered, such as Connected apps in an app without [MCP](#oauth-for-mcp-clients) and Access tokens in an app without [personal access tokens](personal-access-tokens.md). `DeleteAccount` leaves itself out when the app turns [account deletion](#deleting-the-account) off, `PersonalMail` in an app without [personal mail](email.md#from-someones-own-mailbox), and `Connections` when no workflow plugin declares a [connection](workflows.md#connecting-an-account).
|
|
198
199
|
|
|
199
|
-
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:
|
|
200
|
+
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`, `tokens`), so the page lists the ones it keeps beside its own:
|
|
200
201
|
|
|
201
202
|
```tsx
|
|
202
203
|
// config/account.tsx
|
|
@@ -408,6 +409,7 @@ Better Auth's own check of a fresh session, which could only be met by signing o
|
|
|
408
409
|
- adding a passkey;
|
|
409
410
|
- turning on [two-factor authentication](#two-factor-authentication), reading its authenticator link or making new backup codes, on an account without a password (an account with a password gives it instead);
|
|
410
411
|
- unlinking a sign-in provider (`/unlink-account`);
|
|
412
|
+
- making a [personal access token](personal-access-tokens.md#making-one);
|
|
411
413
|
- [deleting the account](#deleting-the-account) without a password.
|
|
412
414
|
|
|
413
415
|
An account with neither a passkey nor a second step has no strong sign-in to confirm with but an [emailed code](#emailed-confirmation-code), so for its first passkey it may give its password instead, where the account page asks: `POST /api/auth/account/confirm-password` with `{ password }`, `session.account.confirmWithPassword(password)` in the client. It counts for adding that passkey only, within 15 minutes, and is no strong sign-in: a [strong sign-in field](data-config.md#recent-strong-sign-in) still asks for one. A wrong password is `INVALID_PASSWORD`, and every try counts toward the account's [password checks](#name-password-and-devices); an account with a passkey or a second step is refused (`403 PASSWORD_CONFIRMATION_NOT_OFFERED`), and so is a [staff session](#staff-sign-in).
|
|
@@ -463,7 +465,7 @@ The guardrails:
|
|
|
463
465
|
- **A strong, recent sign-in:** the provider must report a passkey or a second step (`amr` with `mfa`, `hwk` or `swk`, or an `acr` from `acrValues`), at most 15 minutes old (`auth_time`; the app asks with `max_age`). The person's own two-factor and passkey requirements do not apply to staff.
|
|
464
466
|
- **A reason**, kept in the log with who signed in as whom.
|
|
465
467
|
- **Short and stoppable:** the session lasts 30 minutes (`sessionMinutes`, at most 240), is never extended, ends with the browser, and "Stop staff session" (`POST /api/auth/staff/stop`) ends it and signs the browser out. An API token it got before stops working on its next request, like that of any [ended session](#when-a-token-stops-working).
|
|
466
|
-
- **No takeover:** a staff session cannot change the person's password, email, passkeys, two-factor authentication or
|
|
468
|
+
- **No takeover:** a staff session cannot change the person's password, email, passkeys, two-factor authentication, sessions or personal access tokens, nor save the sign-in policy (`403`, `STAFF_CANNOT_CHANGE_SIGN_IN`).
|
|
467
469
|
- **The app decides:** admins turn staff sign-in off, or have the person emailed each time, with the [sign-in policy](#sign-in-policy).
|
|
468
470
|
- **One way in:** Better Auth's own `/admin/impersonate-user` and `/admin/stop-impersonating` are off (`404`), so app admins cannot sign in as their people.
|
|
469
471
|
- The start is limited to 5 per minute and client; only the browser that started a sign-in can finish it, within 10 minutes and once; and the page it comes back to must be on a trusted origin.
|
|
@@ -685,7 +687,7 @@ With sign-in on, the app's authenticator checks on every request that the token
|
|
|
685
687
|
| Signing out, a revoked session, a stopped staff session | of that session is refused; the person's other sessions keep theirs. |
|
|
686
688
|
| Removal from the organization | naming that organization is refused, unless a global role still enters it. |
|
|
687
689
|
|
|
688
|
-
A refused token is a `401`, as an expired one is, and the client retries the request once with a new token from `/api/auth/token`. Tokens carry their session's id in `sid`; one from [`issueToken`](#tokens-for-scripts-and-curl) names none, and is checked against the user alone.
|
|
690
|
+
A refused token is a `401`, as an expired one is, and the client retries the request once with a new token from `/api/auth/token`. [Personal access tokens](personal-access-tokens.md#when-it-stops) stop the same way. Tokens carry their session's id in `sid`; one from [`issueToken`](#tokens-for-scripts-and-curl) names none, and is checked against the user alone.
|
|
689
691
|
|
|
690
692
|
The cost is two or three lookups by key in the auth store per request: the session by `sid`, the user by `sub`, and with organizations the membership. Nothing is cached, so every server process sees a change at once. An open `/live` stream was admitted when it connected and keeps running until it closes. With `authenticate.jwksUrl` instead of sign-in of its own, the API cannot read the auth store and a token works until it expires, as do tokens of [other apps](#users-of-another-app).
|
|
691
693
|
|
|
@@ -753,7 +755,7 @@ An app moving from Supabase keeps its `supabase.auth` calls and its `@supabase/s
|
|
|
753
755
|
|
|
754
756
|
## Tokens for scripts and curl
|
|
755
757
|
|
|
756
|
-
There is no development login. For scripts, mint a token for an existing user
|
|
758
|
+
There is no development login. A script that runs on its own, such as a weekly job, uses a [personal access token](personal-access-tokens.md) its person makes on the account page, when the app turns them on. For scripts on the host, mint a token for an existing user (the CLI exposes it as `protobase token you@example.com`):
|
|
757
759
|
|
|
758
760
|
```ts
|
|
759
761
|
import { loadProjectAuth } from '@protobase/cli/auth'
|
|
@@ -399,7 +399,7 @@ Everyone who can sign in, for admins: find them by address, tick their roles, bl
|
|
|
399
399
|
|
|
400
400
|
### Account blocks
|
|
401
401
|
|
|
402
|
-
`Profile`, `Password`, `Passkeys`, `TwoFactor`, `ConnectedAccounts`, `PersonalMail`, `Connections`, `Devices`, `ConnectedApps` and `DeleteAccount` 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 [mailbox](email.md#from-someones-own-mailbox) they linked for the app to send mail from, the [accounts they connected](workflows.md#connecting-an-account) for their workflows, the devices signed in as them (each one but this one to [sign out](auth.md#name-password-and-devices)), the apps such as MCP clients they allowed to act as them, below the app's MCP address to connect one, and the [deletion of their account](auth.md#deleting-the-account). 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, `PersonalMail` without `auth.personalMail`, `Connections` when no workflow plugin declares a connection, `ConnectedApps` without MCP, `DeleteAccount` with `auth.accountDeletion: false`. 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.
|
|
402
|
+
`Profile`, `Password`, `Passkeys`, `TwoFactor`, `ConnectedAccounts`, `PersonalMail`, `Connections`, `Devices`, `ConnectedApps`, `PersonalAccessTokens` and `DeleteAccount` 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 [mailbox](email.md#from-someones-own-mailbox) they linked for the app to send mail from, the [accounts they connected](workflows.md#connecting-an-account) for their workflows, the devices signed in as them (each one but this one to [sign out](auth.md#name-password-and-devices)), the apps such as MCP clients they allowed to act as them, below the app's MCP address to connect one, their [personal access tokens](personal-access-tokens.md) for scripts, and the [deletion of their account](auth.md#deleting-the-account). 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, `PersonalMail` without `auth.personalMail`, `Connections` when no workflow plugin declares a connection, `ConnectedApps` without MCP, `PersonalAccessTokens` without `auth.personalAccessTokens`, `DeleteAccount` with `auth.accountDeletion: false`. 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.
|
|
403
403
|
|
|
404
404
|
```tsx
|
|
405
405
|
export const account = page('account',
|
|
@@ -306,6 +306,17 @@ Turns on the OAuth provider for MCP clients, and with it the MCP endpoint: a cli
|
|
|
306
306
|
export default defineConfig({ auth: { mcp: true } })
|
|
307
307
|
```
|
|
308
308
|
|
|
309
|
+
## auth.personalAccessTokens
|
|
310
|
+
|
|
311
|
+
- **Type:** `{ prefix: string }`
|
|
312
|
+
- **Default:** off
|
|
313
|
+
|
|
314
|
+
Turns on personal access tokens: a signed-in person makes long-lived tokens on their account page, for a script to call the app's API as them with `Authorization: Bearer <token>`. `prefix` starts every token, lowercase letters, digits and underscores ending in `_`; it has no default, and the server refuses to start without it or with another. See [Personal access tokens](../personal-access-tokens.md).
|
|
315
|
+
|
|
316
|
+
```ts
|
|
317
|
+
export default defineConfig({ auth: { personalAccessTokens: { prefix: 'invoices_' } } })
|
|
318
|
+
```
|
|
319
|
+
|
|
309
320
|
## authenticate
|
|
310
321
|
|
|
311
322
|
- **Type:** `AuthenticateSettings`
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
<!-- Generated by scripts/protobase-skill.ts from docs/website/src/content/docs/reference/personal-access-tokens.md: run `bun run docs:skill`, do not edit. -->
|
|
2
|
+
|
|
3
|
+
# Personal access tokens
|
|
4
|
+
|
|
5
|
+
Long-lived tokens people make on their account page, so a script calls the app's API as them.
|
|
6
|
+
|
|
7
|
+
A personal access token lets a script or another app call the app's API as the person who made it, without a password and without signing in again on every run, such as a weekly job that drafts invoices. The person makes it on their [account page](auth.md#account-page), copies it into the script once, sees when it was last used, and revokes it at any time.
|
|
8
|
+
|
|
9
|
+
## Turning them on
|
|
10
|
+
|
|
11
|
+
They are off by default. `auth.personalAccessTokens` turns them on, with the prefix every token of the app starts with:
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
// protobase.config.ts
|
|
15
|
+
export default defineConfig({
|
|
16
|
+
auth: { personalAccessTokens: { prefix: 'invoices_' } },
|
|
17
|
+
})
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
The prefix is lowercase letters, digits and underscores, ending in `_`, and has no default: name it after the app, so a token found in a log or a commit says where it works. With the setting and no prefix, or a prefix of other characters, the server refuses to start and names the problem.
|
|
21
|
+
|
|
22
|
+
The tokens live in the auth store's `personal_access_token` table, which every store has from [migration](auth.md#migrations) 8 on, whether the app turns the tokens on or not: `protobase auth migration` writes it for an app upgrading from an earlier Protobase.
|
|
23
|
+
|
|
24
|
+
## Making one
|
|
25
|
+
|
|
26
|
+
The account page's Access tokens tab, at `/-/account/tokens`, lists the person's tokens with their name, when each was made, when it expires and when it was last used, and the role and organization it acts with, and revokes any of them after asking. New token asks for a name and an expiry: in 30 days, in 90 days, in a year, or never. The new token is shown once, to copy: the app keeps only its SHA-256 hash, so nobody can show it again. The tab is not offered in an app without the setting.
|
|
27
|
+
|
|
28
|
+
A token acts with the role, and with [organizations](auth.md#organizations) the organization, the session that made it works in, as its own tokens would. Someone with several roles who wants a token for another one [switches role](auth.md#active-role) first. Someone with no role there cannot make one (`403 NO_ROLE`).
|
|
29
|
+
|
|
30
|
+
- A session that signed in more than a day ago [confirms it's them](auth.md#confirming-an-account-change) first, in place, since a token acts as them long after that session ends.
|
|
31
|
+
- A [staff session](auth.md#staff-sign-in) cannot make or revoke a token (`STAFF_CANNOT_CHANGE_SIGN_IN`); it may see the list.
|
|
32
|
+
- An account in `PROTOBASE_LOCKED_ACCOUNTS`, such as a demo's shared account, cannot make or revoke one (`403 ACCOUNT_LOCKED`).
|
|
33
|
+
|
|
34
|
+
## Using one
|
|
35
|
+
|
|
36
|
+
Send it as `Authorization: Bearer <token>`, wherever the app's own tokens work: the [resources API](api.md), [API functions](../guides/api-functions.md), [live updates](live.md) and the [MCP endpoint](mcp.md).
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
curl -G -H "Authorization: Bearer $INVOICES_TOKEN" --data-urlencode 'filter=status = "draft"' https://erp.example.com/api/v1/invoices
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
A request with it runs as the token's user, with its role, its organization and the app's [access rules](access.md), as that person's own session would. It stands for no sign-in, so what only the person's own sign-in may do is refused, as with [`protobase token`](auth.md#tokens-for-scripts-and-curl): registering a device for push notifications, or a value that needs a [recent strong sign-in](auth.md#recent-strong-sign-in). At the MCP endpoint the token is the client, with the endpoint's scope.
|
|
43
|
+
|
|
44
|
+
A token is the prefix, 40 random characters and a 6-character checksum of both, all after the prefix in base62 (`0-9`, `A-Z`, `a-z`), so a double-click selects it whole. A token whose checksum does not match is refused before the store is read, so a typo or a made-up token costs no lookup. Each request with a valid one reads the store as a session's token does: the token by its hash, the user, and with organizations the membership. Its last use is noted at most once a minute.
|
|
45
|
+
|
|
46
|
+
## When it stops
|
|
47
|
+
|
|
48
|
+
These take effect on the next request, as for the app's own tokens (see [When a token stops working](auth.md#when-a-token-stops-working)); a refused token is a `401` problem with `WWW-Authenticate: Bearer`:
|
|
49
|
+
|
|
50
|
+
| Change | The token |
|
|
51
|
+
| --- | --- |
|
|
52
|
+
| Revoked on the account page | is refused, and gone from the list. |
|
|
53
|
+
| Its expiry passed | is refused. It stays in the list, marked with when it expired, until revoked. |
|
|
54
|
+
| A ban (`/admin/ban-user`, `protobase users disable`) | is refused until the ban runs out or is lifted. |
|
|
55
|
+
| The user deleted | is refused, and deleted with them. |
|
|
56
|
+
| The role it carries taken away | is refused, even when the person still holds another role. |
|
|
57
|
+
| Removal from its organization | is refused, unless the role it carries is a global one, which still enters it. The organization's deletion deletes it. |
|
|
58
|
+
|
|
59
|
+
Signing out, a password change and signing out everywhere leave the person's tokens working, since a script holds them and not a browser: revoke them on the account page.
|
|
60
|
+
|
|
61
|
+
## The API
|
|
62
|
+
|
|
63
|
+
The account page calls these, under `/api/auth`, with the session cookie; each acts on the signed-in person's own tokens only. The client has them in `session.account`:
|
|
64
|
+
|
|
65
|
+
| Client | Endpoint |
|
|
66
|
+
| --- | --- |
|
|
67
|
+
| `personalAccessTokens()` | `GET /account/personal-access-tokens`: `{ tokens: [{ id, name, role, organization?, createdAt, expiresAt?, lastUsedAt? }] }`, newest first, with the role's label and the organization's name |
|
|
68
|
+
| `createPersonalAccessToken({ name, expiresInDays? })` | `POST /account/personal-access-tokens/create`: `{ token, personalAccessToken }`. `name` is 1 to 100 characters, `expiresInDays` 1 to 3650; without it the token never expires |
|
|
69
|
+
| `revokePersonalAccessToken(id)` | `POST /account/personal-access-tokens/revoke` with `{ id }`: deletes it; one that is gone already is no error |
|
|
70
|
+
|
|
71
|
+
`GET /api/auth/status` answers `"personalAccessTokens": true` when the app turns them on. The `PersonalAccessTokens` [block](blocks.md#account-blocks) draws the list, for an account page of the app's own.
|
|
72
|
+
|
|
73
|
+
They are tokens of a person: a token limited to some resources or operations, a token of an organization or of the app itself, and an admin managing other people's tokens are not offered. <gap>A token cannot be limited to some resources or operations because scoped tokens are not implemented.</gap>
|