@protobase/cli 0.29.0 → 0.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/package.js +1 -1
- package/dist/serve/client-address.js +34 -0
- package/dist/serve/env.js +3 -1
- package/dist/serve/lifecycle.js +2 -1
- package/package.json +7 -6
- package/skills/protobase/references/guides/deploy.md +1 -1
- package/skills/protobase/references/reference/auth.md +30 -4
- package/skills/protobase/references/reference/cli.md +2 -1
- package/skills/protobase/references/reference/forms.md +1 -1
package/dist/cli/package.js
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { findInvalidTrustedProxies, getIPFromHeader } from "@better-auth/core/utils/ip";
|
|
2
|
+
//#region src/serve/client-address.ts
|
|
3
|
+
/** The proxies whose `X-Forwarded-For` is believed: addresses or CIDR ranges, comma separated (PROTOBASE_TRUSTED_PROXIES). */
|
|
4
|
+
const readTrustedProxies = (value) => {
|
|
5
|
+
const proxies = (value ?? "").split(",").map((entry) => entry.trim()).filter(Boolean);
|
|
6
|
+
const invalid = findInvalidTrustedProxies(proxies);
|
|
7
|
+
if (invalid.length > 0) throw new Error(`PROTOBASE_TRUSTED_PROXIES must be addresses or CIDR ranges, comma separated, not "${invalid.join(", ")}"`);
|
|
8
|
+
return proxies;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* The client a request comes from: the socket's peer, or, when that is one of `trustedProxies`, the rightmost address
|
|
12
|
+
* of its `X-Forwarded-For` that is not one, as each proxy appends the address it took the request from. A chain of
|
|
13
|
+
* trusted proxies only, or one with an entry that is no address, leaves the peer.
|
|
14
|
+
*/
|
|
15
|
+
const clientAddress = (peer, forwardedFor, trustedProxies) => {
|
|
16
|
+
const chain = trustedProxies.length > 0 && forwardedFor ? `${forwardedFor}, ${peer}` : peer;
|
|
17
|
+
return getIPFromHeader(chain, {
|
|
18
|
+
trustedProxies,
|
|
19
|
+
ipv6Subnet: 128
|
|
20
|
+
}) ?? peer;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* `fetch` with each request's `X-Forwarded-For` replaced by its client's one address, which the sign-in and form rate
|
|
24
|
+
* limits key on and audit events record, so a client never picks its own bucket. Without a peer, a closed socket, the
|
|
25
|
+
* header is dropped.
|
|
26
|
+
*/
|
|
27
|
+
const withClientAddress = (fetch, trustedProxies) => (request, env) => {
|
|
28
|
+
const peer = env.incoming.socket.remoteAddress;
|
|
29
|
+
if (peer) request.headers.set("x-forwarded-for", clientAddress(peer, request.headers.get("x-forwarded-for"), trustedProxies));
|
|
30
|
+
else request.headers.delete("x-forwarded-for");
|
|
31
|
+
return fetch(request, env);
|
|
32
|
+
};
|
|
33
|
+
//#endregion
|
|
34
|
+
export { clientAddress, readTrustedProxies, withClientAddress };
|
package/dist/serve/env.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { readTrustedProxies } from "./client-address.js";
|
|
1
2
|
//#region src/serve/env.ts
|
|
2
3
|
const defaultPort = 8787;
|
|
3
4
|
const readBoolean = (env, name, fallback) => {
|
|
@@ -21,7 +22,8 @@ const readServeEnv = (env) => {
|
|
|
21
22
|
filesCleanupMinutes: minutes,
|
|
22
23
|
runJobs: readBoolean(env, "PROTOBASE_JOBS", true),
|
|
23
24
|
startupChecks: readBoolean(env, "PROTOBASE_STARTUP_CHECKS", true),
|
|
24
|
-
...env.PROTOBASE_JOBS_DRAIN_TOKEN && { drainToken: env.PROTOBASE_JOBS_DRAIN_TOKEN }
|
|
25
|
+
...env.PROTOBASE_JOBS_DRAIN_TOKEN && { drainToken: env.PROTOBASE_JOBS_DRAIN_TOKEN },
|
|
26
|
+
trustedProxies: readTrustedProxies(env.PROTOBASE_TRUSTED_PROXIES)
|
|
25
27
|
};
|
|
26
28
|
};
|
|
27
29
|
//#endregion
|
package/dist/serve/lifecycle.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { withClientAddress } from "./client-address.js";
|
|
1
2
|
import { projectAdmin } from "../project/project-admin.js";
|
|
2
3
|
import { createPgDb } from "../project/pg-db.js";
|
|
3
4
|
import { createServeApp } from "./app.js";
|
|
@@ -48,7 +49,7 @@ const startServe = async ({ project, env, createDb = (url) => createPgDb(pg, url
|
|
|
48
49
|
...env.drainToken && { drainToken: env.drainToken }
|
|
49
50
|
});
|
|
50
51
|
const server = createAdaptorServer({
|
|
51
|
-
fetch: app.fetch,
|
|
52
|
+
fetch: withClientAddress(app.fetch, env.trustedProxies),
|
|
52
53
|
overrideGlobalObjects: false,
|
|
53
54
|
websocket: { server: new WebSocketServer({ noServer: true }) }
|
|
54
55
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.0",
|
|
4
4
|
"description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -33,13 +33,14 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
+
"@better-auth/core": "^1.7.7",
|
|
36
37
|
"@hono/node-server": "^2.1.3",
|
|
37
38
|
"@hono/vite-dev-server": "^0.26.1",
|
|
38
|
-
"@protobase/layout": "0.
|
|
39
|
-
"@protobase/query": "0.
|
|
40
|
-
"@protobase/schema": "0.
|
|
41
|
-
"@protobase/server": "0.
|
|
42
|
-
"@protobase/ui": "0.
|
|
39
|
+
"@protobase/layout": "0.30.0",
|
|
40
|
+
"@protobase/query": "0.30.0",
|
|
41
|
+
"@protobase/schema": "0.30.0",
|
|
42
|
+
"@protobase/server": "0.30.0",
|
|
43
|
+
"@protobase/ui": "0.30.0",
|
|
43
44
|
"@react-email/render": "^2.1.0",
|
|
44
45
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
45
46
|
"@tailwindcss/vite": "^4.3.3",
|
|
@@ -27,7 +27,7 @@ dist/
|
|
|
27
27
|
plugins and the app's version
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
-
The host serves `public/` itself and sends only the manifest's `api` paths to the runtime (and `/.well-known/webauthn`, for an app on [several origins](../reference/auth.md#several-origins))), so loading the UI never needs a running container. The runtime serves the API alone; `protobase serve dist` serves the whole folder the same way, to check a bundle locally. The host passes `DATABASE_URL`, `PORT` (default 8787) and optionally `PROTOBASE_DB_CONNECTIONS` (the connections the app may open, so its functions and jobs leave one to requests, see [`serve`](../reference/cli.md#serve))), `REQUEST_LOG`, `PROTOBASE_SMTP_URL` and `PROTOBASE_MAIL_FROM` (the mail server and sender for [password reset](../reference/auth.md#password-reset)) and emailed sign-in codes) `PROTOBASE_APP_NAME` (the app's name in that mail, see [`appName`](../reference/auth.md#configuration))) `PROTOBASE_SIGN_IN_*` (a provider people with an account sign in with, the [platform sign-in provider](../reference/auth.md#platform-sign-in-provider))) `PROTOBASE_OPERATOR_*` (the provider its staff sign in with for [staff sign-in](../reference/auth.md#staff-sign-in))), `PROTOBASE_ORIGINS` and `PROTOBASE_PASSKEY_DOMAIN` (the app's [other origins](../reference/auth.md#several-origins)) and its passkey domain) `PROTOBASE_CORS_ORIGINS` (the websites that may call its API, see [CORS](../reference/api.md#cors))) and `PROTOBASE_SENTRY_DSN` (the app's [error tracker](../reference/api.md#error-reporting))), plus the project's own settings (`BETTER_AUTH_SECRET`, ...). The runtime and the config module are plain JavaScript for Bun: no install, no TypeScript, no writes. The runtime supplies protobase and the dependencies it runs on the server (`pg`, `postgres`, `kysely`, `better-auth`, ...), so the config module carries only the project's code and the other packages it uses. The runtime serves only bundles built by a compatible Protobase version, below 1.0 the same minor (see [Versioning](../reference/versioning.md#bundles-and-runtimes))), so rebuild the bundle when the host's runtime moves to another one. Nothing in the bundle or the runtime changes the database: run the project's `db:migrate`, which applies its migrations and those of the auth schema, before a new version serves it, with no other writes while it runs. The runtime refuses to start while the auth schema lacks a table or column the new version needs (see [migrations](../reference/auth.md#migrations))). The manifest format and the routing rules are in the CLI reference: [`build`](../reference/cli.md#build)), [`build-serve`](../reference/cli.md#build-serve)) and [`serve`](../reference/cli.md#serve)).
|
|
30
|
+
The host serves `public/` itself and sends only the manifest's `api` paths to the runtime (and `/.well-known/webauthn`, for an app on [several origins](../reference/auth.md#several-origins))), so loading the UI never needs a running container. The runtime serves the API alone; `protobase serve dist` serves the whole folder the same way, to check a bundle locally. The host passes `DATABASE_URL`, `PORT` (default 8787) and optionally `PROTOBASE_DB_CONNECTIONS` (the connections the app may open, so its functions and jobs leave one to requests, see [`serve`](../reference/cli.md#serve))), `REQUEST_LOG`, `PROTOBASE_SMTP_URL` and `PROTOBASE_MAIL_FROM` (the mail server and sender for [password reset](../reference/auth.md#password-reset)) and emailed sign-in codes) `PROTOBASE_APP_NAME` (the app's name in that mail, see [`appName`](../reference/auth.md#configuration))) `PROTOBASE_SIGN_IN_*` (a provider people with an account sign in with, the [platform sign-in provider](../reference/auth.md#platform-sign-in-provider))) `PROTOBASE_OPERATOR_*` (the provider its staff sign in with for [staff sign-in](../reference/auth.md#staff-sign-in))), `PROTOBASE_ORIGINS` and `PROTOBASE_PASSKEY_DOMAIN` (the app's [other origins](../reference/auth.md#several-origins)) and its passkey domain) `PROTOBASE_CORS_ORIGINS` (the websites that may call its API, see [CORS](../reference/api.md#cors))), `PROTOBASE_TRUSTED_PROXIES` (the proxies in front of the runtime, whose `X-Forwarded-For` names the client the sign-in limits count, see [Client addresses](../reference/auth.md#client-addresses))) and `PROTOBASE_SENTRY_DSN` (the app's [error tracker](../reference/api.md#error-reporting))), plus the project's own settings (`BETTER_AUTH_SECRET`, ...). The runtime and the config module are plain JavaScript for Bun: no install, no TypeScript, no writes. The runtime supplies protobase and the dependencies it runs on the server (`pg`, `postgres`, `kysely`, `better-auth`, ...), so the config module carries only the project's code and the other packages it uses. The runtime serves only bundles built by a compatible Protobase version, below 1.0 the same minor (see [Versioning](../reference/versioning.md#bundles-and-runtimes))), so rebuild the bundle when the host's runtime moves to another one. Nothing in the bundle or the runtime changes the database: run the project's `db:migrate`, which applies its migrations and those of the auth schema, before a new version serves it, with no other writes while it runs. The runtime refuses to start while the auth schema lacks a table or column the new version needs (see [migrations](../reference/auth.md#migrations))). The manifest format and the routing rules are in the CLI reference: [`build`](../reference/cli.md#build)), [`build-serve`](../reference/cli.md#build-serve)) and [`serve`](../reference/cli.md#serve)).
|
|
31
31
|
|
|
32
32
|
## Images
|
|
33
33
|
|
|
@@ -80,12 +80,22 @@ The columns Better Auth needs that the table lacks, filled from what the other s
|
|
|
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.16.0.0/12`; see [Client addresses](#client-addresses) |
|
|
83
84
|
|
|
84
85
|
- Cookies are `SameSite=Lax`, and `Secure` when `BETTER_AUTH_URL` is https.
|
|
85
|
-
- 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);
|
|
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.
|
|
86
87
|
- New passwords need at least 12 characters.
|
|
87
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)).
|
|
88
89
|
|
|
90
|
+
### Client addresses
|
|
91
|
+
|
|
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
|
+
|
|
94
|
+
- Without `PROTOBASE_TRUSTED_PROXIES`, the client is the address the connection comes from. That fits a server the clients reach directly, such as `docker run -p 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 range it connects from, such as `172.16.0.0/12` for a Docker network, and 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
|
+
|
|
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
|
+
|
|
89
99
|
## First run
|
|
90
100
|
|
|
91
101
|
Accounts are never created over the web while the store is empty: there is no setup route, and [open sign-up](#open-sign-up), when an app turns it on, waits for the first admin, so a freshly deployed URL cannot be claimed by whoever reaches it first. The first admin is created on the host, with the CLI (`protobase users create you@example.com --generate-password`, or `--no-password` for an account that signs in by emailed code, passkey or a sign-in provider only) or from code:
|
|
@@ -254,7 +264,7 @@ The guardrails:
|
|
|
254
264
|
- **Permission:** the ID token's `groups` claim must hold the configured group (default `protobase-staff-access`).
|
|
255
265
|
- **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.
|
|
256
266
|
- **A reason**, kept in the log with who signed in as whom.
|
|
257
|
-
- **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
|
|
267
|
+
- **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).
|
|
258
268
|
- **No takeover:** a staff session cannot change the person's password, email, passkeys, two-factor authentication or sessions, nor save the sign-in policy (`403`, `STAFF_CANNOT_CHANGE_SIGN_IN`).
|
|
259
269
|
- **The app decides:** admins turn staff sign-in off, or have the person emailed each time, with the [sign-in policy](#sign-in-policy).
|
|
260
270
|
- **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.
|
|
@@ -424,7 +434,7 @@ It is Better Auth's organization plugin, with its tables named in snake_case (`o
|
|
|
424
434
|
|
|
425
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`.
|
|
426
436
|
|
|
427
|
-
**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
|
|
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.
|
|
428
438
|
|
|
429
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.
|
|
430
440
|
|
|
@@ -444,6 +454,22 @@ Sign in at `POST /api/auth/sign-in/email` (or with a code or passkey), then `GET
|
|
|
444
454
|
|
|
445
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.
|
|
446
456
|
|
|
457
|
+
### When a token stops working
|
|
458
|
+
|
|
459
|
+
With `auth`, `betterAuthAuthenticator` checks on every request that the token still stands, so these take effect on the next request every route that authenticates sees (the resources API, `/api/meta`, batches, functions, files and new `/live` streams), not when the token expires:
|
|
460
|
+
|
|
461
|
+
| Change | The token |
|
|
462
|
+
| --- | --- |
|
|
463
|
+
| A ban (`/admin/ban-user`, `protobase users disable`) | is refused until the ban runs out or is lifted; a ban ends the sessions too, so a new token takes signing in again. |
|
|
464
|
+
| A role taken away (`/admin/set-role`, `setUserRole`, a membership's app roles) | carrying that role is refused; the client's retry gets a token from its session with the roles left. A token carrying fewer roles than held keeps working. |
|
|
465
|
+
| The user deleted | is refused. |
|
|
466
|
+
| Signing out, a revoked session, a stopped staff session | of that session is refused; the person's other sessions keep theirs. |
|
|
467
|
+
| Removal from the organization | naming that organization is refused, unless a global role still enters it. |
|
|
468
|
+
|
|
469
|
+
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.
|
|
470
|
+
|
|
471
|
+
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 `jwksUrl` instead of `auth`, the API cannot read the auth store and a token works until it expires, as do tokens of [other apps](#users-of-another-app).
|
|
472
|
+
|
|
447
473
|
## Users of another app
|
|
448
474
|
|
|
449
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:
|
|
@@ -479,7 +505,7 @@ import { issueToken } from '@protobase/server'
|
|
|
479
505
|
const { token, expiresAt } = await issueToken(auth, { email: 'you@example.com', ttlSeconds: 3600 }) // default 15 minutes, at most 24 hours
|
|
480
506
|
```
|
|
481
507
|
|
|
482
|
-
It is signed with the same keys and carries the same claims as a token from `/api/auth/token`, with the role the user last chose, else their first, so the API treats it as any other. Banned and unknown users get an error. There is no HTTP route for this.
|
|
508
|
+
It is signed with the same keys and carries the same claims as a token from `/api/auth/token`, with the role the user last chose, else their first, so the API treats it as any other, and a ban, a role taken away or the user deleted ends it before it expires. Banned and unknown users get an error. There is no HTTP route for this.
|
|
483
509
|
|
|
484
510
|
## Several origins
|
|
485
511
|
|
|
@@ -377,6 +377,7 @@ Serves the API of a bundle from `protobase build` and owns the process around it
|
|
|
377
377
|
| `PROTOBASE_JOBS` | `false` runs none of the app's [jobs](jobs.md)) in this process, which still enqueues them; default `true` |
|
|
378
378
|
| `PROTOBASE_STARTUP_CHECKS` | `false` skips the startup reads of the auth, changes, computed columns, webhooks and jobs schemas, which make a start slower; default `true`. Set it only to restart a bundle that already started on this database, such as when a platform wakes a sleeping app, never for a new bundle or after its migrations ran |
|
|
379
379
|
| `PROTOBASE_SHELL` | `protobase serve <bundle>` only: a shell folder, such as the `/opt/protobase/shell` of a protobase image or `@protobase/ui`'s `dist/shell`, to serve the bundle's app from (see [its own shell](#serve)) |
|
|
380
|
+
| `PROTOBASE_TRUSTED_PROXIES` | the proxies in front of the server, addresses or CIDR ranges, comma separated: a request from one of them names its client in `X-Forwarded-For`; without it the client is the connection's address ([Client addresses](auth.md#client-addresses))) |
|
|
380
381
|
| `PROTOBASE_JOBS_DRAIN_TOKEN` | the operator's bearer token for `POST /api/jobs/drain`, which [runs the due jobs](jobs.md#hosts-that-sleep)) of a host that lets the app sleep; without it there is no such endpoint |
|
|
381
382
|
|
|
382
383
|
Better Auth and other settings are the project's own variables (`BETTER_AUTH_SECRET`, `BETTER_AUTH_URL`, ...), read by its config. `protobase serve` also loads the nearest `.env`, like `dev`; the runtime takes the environment as it is.
|
|
@@ -423,7 +424,7 @@ Run inside a project whose `protobase.config.ts` exports `auth` (Better Auth). T
|
|
|
423
424
|
|
|
424
425
|
The password is typed at a hidden prompt with confirmation, read from stdin with `--password-stdin` (for scripts, e.g. `pass show erp | protobase users create me@example.com --password-stdin`), or generated with `--generate-password` and printed once. `--no-password` makes an account without one, which signs in by [emailed code](auth.md#emailed-sign-in-codes)), passkey or a sign-in provider, as with an app whose [sign-in policy](auth.md#sign-in-policy)) turns passwords off. A password is never accepted as an argument, since it would end up in shell history. `users list` prints email, role and creation date (and `disabled` for banned users), never credentials.
|
|
425
426
|
|
|
426
|
-
`delete` asks you to type the email back (or pass `--yes`), and needs a terminal otherwise. `delete`, `set-role` and `disable` refuse to touch the last admin, so the project cannot lock itself out. `disable` bans the user and revokes their sessions; tokens already issued stop working
|
|
427
|
+
`delete` asks you to type the email back (or pass `--yes`), and needs a terminal otherwise. `delete`, `set-role` and `disable` refuse to touch the last admin, so the project cannot lock itself out. `disable` bans the user and revokes their sessions; tokens already issued stop working on their next request, and `protobase token` refuses disabled users. `enable` lifts the ban. `protobase dev` prints "No users yet. Create the first admin with: protobase users create you@example.com" at startup while the user table is empty.
|
|
427
428
|
|
|
428
429
|
With [organizations](auth.md#organizations)), `--role` is the user's global role (none by default) and `--organization` adds the new user to an organization, with `--org-role` (`owner`, `admin`, or `member`, the default) and `--app-roles` there.
|
|
429
430
|
|
|
@@ -112,7 +112,7 @@ export const newContactRequests = subscription('newContactRequests', {
|
|
|
112
112
|
|
|
113
113
|
## Rate limit
|
|
114
114
|
|
|
115
|
-
Each client may send a form `perMinute` times a minute, 5 by default, as many as it may try to sign in. Past that, the form answers `429` with `Retry-After`. A client is known by its address
|
|
115
|
+
Each client may send a form `perMinute` times a minute, 5 by default, as many as it may try to sign in. Past that, the form answers `429` with `Retry-After`. A client is known by its address, as the sign-in limit knows it: see [Client addresses](auth.md#client-addresses)), and `PROTOBASE_TRUSTED_PROXIES` behind a proxy. The count is kept in each server process's memory, so with several instances each counts on its own, and a restart starts over.
|
|
116
116
|
|
|
117
117
|
## Bot check
|
|
118
118
|
|