@quickback-dev/cli 0.67.0 → 0.67.2
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/index.js +1 -1
- package/dist/lib/file-loader.d.ts.map +1 -1
- package/dist/lib/file-loader.js +1 -0
- package/dist/lib/file-loader.js.map +1 -1
- package/dist/skill/docs/api/batch-operations.md +5 -0
- package/dist/skill/docs/api/crud.md +8 -0
- package/dist/skill/docs/api/errors.md +7 -4
- package/dist/skill/docs/api/openapi.md +1 -0
- package/dist/skill/docs/configure/auth.md +26 -0
- package/dist/skill/docs/configure/index.md +28 -9
- package/dist/skill/docs/configure/providers.md +12 -0
- package/dist/skill/docs/define/access.md +15 -2
- package/dist/skill/docs/define/actions/scoped-db.md +1 -0
- package/dist/skill/docs/define/authz-roles.md +1 -1
- package/dist/skill/docs/define/encryption.md +39 -7
- package/dist/skill/docs/define/firewall.md +6 -0
- package/dist/skill/docs/define/schema.md +31 -2
- package/dist/skill/docs/platform/auth/api-keys.md +77 -1
- package/dist/skill/docs/platform/auth/plugins/agent-auth.md +1 -1
- package/dist/skill/docs/platform/auth/plugins/index.md +33 -34
- package/dist/skill/docs/platform/auth/security.md +53 -6
- package/dist/skill/docs/platform/auth/using-auth.md +1 -1
- package/dist/skill/docs/platform/realtime/partyserver-rooms.md +2 -0
- package/dist/skill/docs/platform/storage/r2.md +2 -0
- package/dist/skill/docs/platform/storage/using-kv.md +6 -36
- package/dist/skill/docs/platform/webhooks/inbound.md +2 -1
- package/dist/skill/docs/tooling/cloud-compiler/endpoints.md +4 -0
- package/dist/skill/docs/tooling/cloud-compiler/troubleshooting.md +12 -8
- package/dist/skill/docs/ui/account/features/api-keys.md +2 -1
- package/dist/skill/docs/ui/account/features/index.md +7 -6
- package/dist/skill/docs/ui/account/features/passwordless.md +1 -1
- package/dist/skill/docs/ui/account/hooks.md +50 -2
- package/dist/skill/docs/ui/account/index.md +2 -2
- package/dist/skill/docs/ui/admin/actions.md +2 -1
- package/package.json +1 -1
- package/src/skill/docs/api/batch-operations.md +5 -0
- package/src/skill/docs/api/crud.md +8 -0
- package/src/skill/docs/api/errors.md +7 -4
- package/src/skill/docs/api/openapi.md +1 -0
- package/src/skill/docs/configure/auth.md +26 -0
- package/src/skill/docs/configure/index.md +28 -9
- package/src/skill/docs/configure/providers.md +12 -0
- package/src/skill/docs/define/access.md +15 -2
- package/src/skill/docs/define/actions/scoped-db.md +1 -0
- package/src/skill/docs/define/authz-roles.md +1 -1
- package/src/skill/docs/define/encryption.md +39 -7
- package/src/skill/docs/define/firewall.md +6 -0
- package/src/skill/docs/define/schema.md +31 -2
- package/src/skill/docs/platform/auth/api-keys.md +77 -1
- package/src/skill/docs/platform/auth/plugins/agent-auth.md +1 -1
- package/src/skill/docs/platform/auth/plugins/index.md +33 -34
- package/src/skill/docs/platform/auth/security.md +53 -6
- package/src/skill/docs/platform/auth/using-auth.md +1 -1
- package/src/skill/docs/platform/realtime/partyserver-rooms.md +2 -0
- package/src/skill/docs/platform/storage/r2.md +2 -0
- package/src/skill/docs/platform/storage/using-kv.md +6 -36
- package/src/skill/docs/platform/webhooks/inbound.md +2 -1
- package/src/skill/docs/tooling/cloud-compiler/endpoints.md +4 -0
- package/src/skill/docs/tooling/cloud-compiler/troubleshooting.md +12 -8
- package/src/skill/docs/ui/account/features/api-keys.md +2 -1
- package/src/skill/docs/ui/account/features/index.md +7 -6
- package/src/skill/docs/ui/account/features/passwordless.md +1 -1
- package/src/skill/docs/ui/account/hooks.md +50 -2
- package/src/skill/docs/ui/account/index.md +2 -2
- package/src/skill/docs/ui/admin/actions.md +2 -1
|
@@ -16,9 +16,85 @@ The compiler validates the key by calling the Quickback API's Better Auth `GET /
|
|
|
16
16
|
|
|
17
17
|
## What a key can reach
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
Send a key as `x-api-key: <key>`, or — for keys that carry the project prefix (every key created since prefixes were added) — as `Authorization: Bearer <key>`. Older unprefixed keys work only through `x-api-key`. Either way a key authenticates two things:
|
|
20
20
|
|
|
21
21
|
- **Your API** (`/api/*`) — the auth middleware verifies the key and resolves its owner's role in the organization named by the key's `metadata.organizationId`.
|
|
22
22
|
- **`GET /auth/v1/get-session`** — the one Better Auth endpoint where a key stands in for its owner's session (the key-validation "whoami").
|
|
23
23
|
|
|
24
24
|
Every other Better Auth endpoint ignores the header and answers as for an unauthenticated caller: a key cannot mint an identity JWT (`GET /auth/v1/token`), list sessions, create or manage keys, change the user, register a passkey, or act on organizations. Those need a real session.
|
|
25
|
+
|
|
26
|
+
The generated MCP endpoint (`POST /mcp`) is bearer-only: it forwards `Authorization`, not `x-api-key`, to the routes its tools call. So an MCP client uses a prefixed key as `Authorization: Bearer <key>`. A scoped key may open `/mcp` (and list tools); each tool call re-enters the REST route it wraps, where the key's scopes are checked — a `tasks:read` key can call the list-tasks tool but gets `403 ACCESS_KEY_SCOPE_REQUIRED` from the create-task tool.
|
|
27
|
+
|
|
28
|
+
The prefix is what makes the Bearer form unambiguous: `plugins.apiKey.prefix` must end in `_` or `-` (Better Auth session tokens are alphanumeric, so they can never start with one) and must not start with `eyJ` (a JWT).
|
|
29
|
+
|
|
30
|
+
## Scopes
|
|
31
|
+
|
|
32
|
+
By default a key carries its owner's **full** role in the organization it names. Give it `metadata.scopes` to narrow that — for an agent, a CI job, or an integration that only needs part of the API:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
curl -X POST https://api.example.com/auth/v1/api-key/create \
|
|
36
|
+
-H "Cookie: ${SESSION_COOKIE}" -H "Content-Type: application/json" \
|
|
37
|
+
-d '{"name":"reporting agent","metadata":{"organizationId":"org_123","scopes":["customers:read","deals:read"]}}'
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The [Account UI](/ui/account/features/api-keys) has a Scopes field for the same thing. The vocabulary is closed:
|
|
41
|
+
|
|
42
|
+
| Scope | Admits |
|
|
43
|
+
|-------|--------|
|
|
44
|
+
| `read` | `GET` / `HEAD` / `OPTIONS` on every route under `/api/v1` |
|
|
45
|
+
| `write` | Every other method under `/api/v1` — create, update, delete, batch, and non-`GET` actions |
|
|
46
|
+
| `<resource>:read` | Reads under `/api/v1/<resource>/` — list, get, views, `GET` actions |
|
|
47
|
+
| `<resource>:write` | Writes under `/api/v1/<resource>/` — including actions mounted there |
|
|
48
|
+
|
|
49
|
+
`<resource>` is the first path segment of a generated resource route (`customers` for `/api/v1/customers`). The method decides read vs write, so a `GET` action is a read. `write` does not imply `read`; list both if the key needs both. Routes outside a resource mount — area/namespace routes (`/api/v1/<scope>/:id/…`), root-mounted standalone actions, `/api/v1/schema` — are reachable only through the global `read` / `write`.
|
|
50
|
+
|
|
51
|
+
**Scopes narrow, they never widen.** The auth middleware checks the scope first; the route's own [Access](/define/access) and [Firewall](/define/firewall) then run with the owner's org role exactly as before. A `customers:write` key held by a `member` still cannot delete what `crud.delete.access` reserves for `admin`.
|
|
52
|
+
|
|
53
|
+
**Outside `/api/v1`, a scoped key is refused.** Storage, realtime tickets, webhooks, FGA, and public discovery routes answer a scoped key with `403`. `/auth/v1/*` is allowed — there the key is only the `get-session` whoami. Use an unscoped key or a session for those surfaces.
|
|
54
|
+
|
|
55
|
+
A denied request is a standard [Problem Details](/api/errors) `403`:
|
|
56
|
+
|
|
57
|
+
```json
|
|
58
|
+
{
|
|
59
|
+
"type": "https://quickback.dev/problems/access-key-scope-required",
|
|
60
|
+
"title": "Access key scope required",
|
|
61
|
+
"status": 403,
|
|
62
|
+
"code": "ACCESS_KEY_SCOPE_REQUIRED",
|
|
63
|
+
"detail": "API key scope does not allow this request",
|
|
64
|
+
"layer": "access",
|
|
65
|
+
"details": { "required": ["customers:write"], "current": ["customers:read"] },
|
|
66
|
+
"hint": "Create a key with the \"customers:write\" scope (or omit scopes for a full-access key)"
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Validation
|
|
71
|
+
|
|
72
|
+
Scopes are checked when a key is created or updated (`POST /auth/v1/api-key/create`, `/api-key/update`). An unknown resource, an unknown verb, an empty list, or a non-array value fails with `400` and `code: "INVALID_API_KEY_SCOPES"`; nothing is normalized. A scope naming a resource that was later removed simply matches nothing. Stored scopes that are not an array of strings fail the key closed (`401 AUTH_INVALID_TOKEN`, `details.reason: "malformed_scopes"`).
|
|
73
|
+
|
|
74
|
+
### Existing keys
|
|
75
|
+
|
|
76
|
+
A key with no `scopes` in its metadata is a full-role key, so every key created before scopes existed keeps working unchanged. Scopes live in `metadata`, which the owner can change through `/api-key/update`; replacing the metadata without `scopes` turns the key back into a full-role key. That is the owner's call — they can always create a full-role key anyway. Scopes protect against a leaked key, not against its owner.
|
|
77
|
+
|
|
78
|
+
Scopes are stored in metadata rather than Better Auth's `permissions` field because `permissions` is server-only: the Account UI and other session clients could not set it.
|
|
79
|
+
|
|
80
|
+
## Key prefix
|
|
81
|
+
|
|
82
|
+
New keys start with a display prefix so they are recognisable in logs and secret scanners. It defaults to the project name, slugged (`my-app` → `my_app_…`). Override it with the object form of the plugin:
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
auth: defineAuth("better-auth", {
|
|
86
|
+
plugins: {
|
|
87
|
+
apiKey: { prefix: "acme_live_" },
|
|
88
|
+
},
|
|
89
|
+
}),
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
The prefix must be 1–32 characters of `A-Z a-z 0-9 _ -`; anything else fails the compile. It is display-only — Better Auth hashes the whole key — so keys created before the prefix existed keep verifying.
|
|
93
|
+
|
|
94
|
+
## Banned owners
|
|
95
|
+
|
|
96
|
+
When the admin plugin bans a user, every API key they own stops working: the API answers `401 AUTH_INVALID_TOKEN` with `details.reason: "owner_banned"`, and `GET /auth/v1/get-session` refuses the key. A ban whose `banExpires` has passed no longer counts, matching the admin plugin. A deleted owner's keys stop working too.
|
|
97
|
+
|
|
98
|
+
## Rate limit
|
|
99
|
+
|
|
100
|
+
Better Auth rate limits each key using the auth config's `rateLimit.window` (seconds) and `rateLimit.max` — 100 requests per 60 seconds by default. The limit is on unless that block sets `enabled: false`. Over the limit the API answers `429 AUTH_RATE_LIMITED`. The values are stamped on each key when it is created, so a change applies to new keys only.
|
|
@@ -128,4 +128,4 @@ When `fromOpenAPI: false`, the emitted call has `capabilities: []` and no proxy
|
|
|
128
128
|
|
|
129
129
|
## Why bearer-only?
|
|
130
130
|
|
|
131
|
-
The MCP and agent surfaces are server-to-server by nature. Cookies on those surfaces add CSRF surface for no benefit (no browser callers), and `x-api-key` was the legacy `apiKey`-plugin path that fragments the auth model. Bearer is the one true channel here.
|
|
131
|
+
The MCP and agent surfaces are server-to-server by nature. Cookies on those surfaces add CSRF surface for no benefit (no browser callers), and `x-api-key` was the legacy `apiKey`-plugin path that fragments the auth model. Bearer is the one true channel here. API keys ride it too: a prefixed key sent as `Authorization: Bearer <key>` is recognised by the auth middleware, so an MCP client can authenticate with a (scoped) API key. See [API Keys](/platform/auth/api-keys#what-a-key-can-reach).
|
|
@@ -40,6 +40,8 @@ export default defineConfig({
|
|
|
40
40
|
- `POST /auth/v1/email-otp/send-verification-otp`
|
|
41
41
|
- `POST /auth/v1/email-otp/verify-otp`
|
|
42
42
|
|
|
43
|
+
Codes are stored hashed and expire after 300 seconds by default; set `plugins: { emailOtp: { expiresIn: 600 } }` to change it — the email states the configured lifetime.
|
|
44
|
+
|
|
43
45
|
**Email readiness check:**
|
|
44
46
|
|
|
45
47
|
Use this to show UI warnings when SES isn't configured.
|
|
@@ -67,11 +69,12 @@ auth: defineAuth("better-auth", {
|
|
|
67
69
|
}),
|
|
68
70
|
```
|
|
69
71
|
|
|
70
|
-
> `emailOtp.disableSignUp` **inherits
|
|
71
|
-
>
|
|
72
|
-
>
|
|
73
|
-
> `
|
|
74
|
-
>
|
|
72
|
+
> `emailOtp.disableSignUp` **inherits `emailAndPassword.disableSignUp: true`**, so
|
|
73
|
+
> the OTP path can't bypass a hard password-signup block. Set
|
|
74
|
+
> `emailOtp: { disableSignUp: false }` explicitly to opt the OTP path back open.
|
|
75
|
+
> `account.auth.signup: false` is different: it sets the invite-only
|
|
76
|
+
> [signup policy](/platform/auth/security#signup-policy), which covers every
|
|
77
|
+
> sign-in method and still admits invitees.
|
|
75
78
|
|
|
76
79
|
|
|
77
80
|
### SMS OTP (with AWS SNS)
|
|
@@ -125,19 +128,23 @@ Optional vars:
|
|
|
125
128
|
|
|
126
129
|
### Magic Links
|
|
127
130
|
|
|
128
|
-
Magic links provide passwordless authentication by
|
|
131
|
+
Magic links provide passwordless authentication by emailing a single-use sign-in link.
|
|
129
132
|
|
|
130
133
|
**Enable in config:**
|
|
131
134
|
|
|
132
135
|
```ts
|
|
133
136
|
auth: defineAuth("better-auth", {
|
|
134
|
-
plugins:
|
|
137
|
+
plugins: { magicLink: { expiresIn: 900 } }, // seconds; default 300
|
|
135
138
|
}),
|
|
136
139
|
```
|
|
137
140
|
|
|
138
141
|
**Endpoints:**
|
|
139
|
-
- `POST /auth/v1/magic-link
|
|
140
|
-
- `GET /auth/v1/magic-link/verify` -
|
|
142
|
+
- `POST /auth/v1/sign-in/magic-link` - Send the magic link email (`{ email, callbackURL? }`)
|
|
143
|
+
- `GET /auth/v1/magic-link/verify` - Spend the token, set the session, redirect to `callbackURL`
|
|
144
|
+
|
|
145
|
+
**The emailed link opens a confirm page.** Mail scanners fetch every link in a message, which would spend a single-use token before the recipient clicks. So the email links to `<ACCOUNT_URL>/magic-link?token=…` — the [Account UI](/ui/account/features/passwordless) confirm page — and only its **Continue signing in** button navigates to `/magic-link/verify`. If you serve your own frontend at `ACCOUNT_URL`, give it a `/magic-link` page that does the same: forward the query string to `/auth/v1/magic-link/verify` on a user click.
|
|
146
|
+
|
|
147
|
+
Tokens are stored hashed, and the email states the configured `expiresIn`.
|
|
141
148
|
|
|
142
149
|
**Disabling sign-up via magic link:**
|
|
143
150
|
|
|
@@ -154,31 +161,28 @@ auth: defineAuth("better-auth", {
|
|
|
154
161
|
}),
|
|
155
162
|
```
|
|
156
163
|
|
|
157
|
-
It inherits
|
|
158
|
-
`
|
|
159
|
-
|
|
164
|
+
It inherits `emailAndPassword.disableSignUp: true` the same way
|
|
165
|
+
`emailOtp.disableSignUp` does; set `magicLink: { disableSignUp: false }` to opt
|
|
166
|
+
it back open. The invite-only [signup policy](/platform/auth/security#signup-policy)
|
|
167
|
+
applies to magic links too.
|
|
160
168
|
|
|
161
|
-
**Email
|
|
169
|
+
**Email delivery:**
|
|
162
170
|
|
|
163
|
-
Magic link emails
|
|
164
|
-
|
|
165
|
-
- `APP_NAME` - Application name in email subject
|
|
166
|
-
- `APP_URL` - Base URL for magic link redirect
|
|
167
|
-
- `EMAIL_FROM` - Sender email address
|
|
168
|
-
- `EMAIL_FROM_NAME` - Sender display name
|
|
171
|
+
Magic link emails go through your configured `email.provider` — Cloudflare Email Sending by default, or AWS SES with the same variables as Email OTP (`APP_NAME`, `EMAIL_FROM`, `EMAIL_FROM_NAME`). `ACCOUNT_URL` sets where the confirm page lives.
|
|
169
172
|
|
|
170
173
|
**Frontend integration:**
|
|
171
174
|
|
|
172
175
|
```ts
|
|
173
|
-
// Request magic link
|
|
174
|
-
await fetch('/auth/v1/magic-link
|
|
176
|
+
// Request a magic link
|
|
177
|
+
await fetch('/auth/v1/sign-in/magic-link', {
|
|
175
178
|
method: 'POST',
|
|
176
179
|
headers: { 'Content-Type': 'application/json' },
|
|
177
|
-
|
|
180
|
+
credentials: 'include',
|
|
181
|
+
body: JSON.stringify({ email: 'user@yourdomain.com', callbackURL: 'https://app.yourdomain.com/' }),
|
|
178
182
|
});
|
|
179
183
|
|
|
180
|
-
//
|
|
181
|
-
//
|
|
184
|
+
// The user opens the link, lands on <ACCOUNT_URL>/magic-link, clicks
|
|
185
|
+
// "Continue signing in", and is redirected to callbackURL signed in.
|
|
182
186
|
```
|
|
183
187
|
|
|
184
188
|
### Passkeys
|
|
@@ -283,18 +287,13 @@ Static, long-lived credentials for cron jobs, scripts, and machine-to-machine in
|
|
|
283
287
|
|
|
284
288
|
**Authenticating requests:**
|
|
285
289
|
|
|
286
|
-
Pass the key as the `x-api-key` header
|
|
290
|
+
Pass the key as the `x-api-key` header, or a prefixed key as `Authorization: Bearer <key>` (query parameters are not accepted, so keys never land in access logs or `Referer`):
|
|
287
291
|
|
|
288
292
|
```bash
|
|
289
|
-
|
|
290
|
-
curl -H "x-api-key: ${KEY}" https://api.example.com/v1/jobs
|
|
291
|
-
|
|
292
|
-
# Query-param form (for clients that can't inject custom headers,
|
|
293
|
-
# e.g., claude.ai's MCP connector)
|
|
294
|
-
curl "https://api.example.com/v1/jobs?api_key=${KEY}"
|
|
293
|
+
curl -H "x-api-key: ${KEY}" https://api.example.com/api/v1/jobs
|
|
295
294
|
```
|
|
296
295
|
|
|
297
|
-
|
|
296
|
+
Sending `x-api-key` together with a session cookie or an `Authorization` header is a `400 AUTH_METHOD_CONFLICT`.
|
|
298
297
|
|
|
299
298
|
**Endpoints (managed by Better Auth):**
|
|
300
299
|
- `POST /auth/v1/api-key/create` — issue a new key (returns the secret once; store it)
|
|
@@ -303,7 +302,7 @@ The header takes precedence when both are present. The query-param form lands in
|
|
|
303
302
|
|
|
304
303
|
These need a real session (cookie or session-token bearer). Under `/auth/v1/*` a key authenticates only `GET /auth/v1/get-session`; every other Better Auth endpoint ignores `x-api-key`, so a leaked key cannot mint JWTs, manage keys, or act on organizations. See [API Keys](/platform/auth/api-keys).
|
|
305
304
|
|
|
306
|
-
Keys can carry organization context via `metadata.organizationId` — when set, the auth middleware looks up the user's role in that org and populates `ctx.roles` accordingly, so a single key inherits the same firewall + access scope as the user who created it.
|
|
305
|
+
Keys can carry organization context via `metadata.organizationId` — when set, the auth middleware looks up the user's role in that org and populates `ctx.roles` accordingly, so a single key inherits the same firewall + access scope as the user who created it. `metadata.scopes` narrows a key to named resources and read/write — see [API Keys → Scopes](/platform/auth/api-keys#scopes). New keys carry a project prefix (`plugins: { apiKey: { prefix } }`), a banned owner's keys stop working, and each key is rate limited.
|
|
307
306
|
|
|
308
307
|
### OAuth Provider (MCP-ready)
|
|
309
308
|
|
|
@@ -395,7 +394,7 @@ Consent management:
|
|
|
395
394
|
|
|
396
395
|
**Account SPA wiring:**
|
|
397
396
|
|
|
398
|
-
The compiled Account SPA already serves `/consent`. When `oauthProvider` is enabled, Better Auth
|
|
397
|
+
The compiled Account SPA already serves `/consent`. When `oauthProvider` is enabled, Better Auth sends unauthenticated users to `${ACCOUNT_URL}/login` and authenticated users to `${ACCOUNT_URL}/consent`. Both URLs carry the signed authorize query (`client_id`, `scope`, repeated `ba_param` keys, `sig`, and so on). The bundled consent screen fetches client metadata via `/oauth2/public-client`, then POSTs the page's query back to `/oauth2/consent` as `oauth_query`. The login page does the same on sign-in. The SPA router keeps that query verbatim, because any rewrite fails the signature check with `invalid_signature`.
|
|
399
398
|
|
|
400
399
|
**Token and tenant context:**
|
|
401
400
|
|
|
@@ -76,6 +76,53 @@ auth: defineAuth("better-auth", {
|
|
|
76
76
|
|
|
77
77
|
---
|
|
78
78
|
|
|
79
|
+
## Signup Policy
|
|
80
|
+
|
|
81
|
+
`signup` decides who may create an account. One server-side gate (Better Auth's `user.create.before`) enforces it on **every** creation path — email + password, email OTP, magic link, and social sign-in — so no sign-in method can be used to slip past it.
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
auth: defineAuth("better-auth", {
|
|
85
|
+
signup: { inviteOnly: true }, // invitations + admin-created only
|
|
86
|
+
// or: signup: { allowedEmailDomains: ["example.com"] } // that domain + invitations
|
|
87
|
+
})
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
| Always admitted | Why |
|
|
91
|
+
|-----------------|-----|
|
|
92
|
+
| Accounts created by an admin (`POST /auth/v1/admin/create-user`) | Operators provision users directly |
|
|
93
|
+
| An email with a **pending, unexpired** organization invitation | Invitees must be able to sign up |
|
|
94
|
+
| The deploy owner's first Cloudflare login | The brokered-deploy owner is promoted to `appmanager` on that login |
|
|
95
|
+
|
|
96
|
+
Everyone else gets `403` with code `SIGNUP_NOT_ALLOWED`. Existing users sign in as before — the gate runs only when an account would be created. `allowedEmailDomains` matches the exact domain (`example.com` admits `me@example.com`, not `me@sub.example.com`).
|
|
97
|
+
|
|
98
|
+
`account.auth.signup: false` is the shorthand for `inviteOnly: true`. The compile fails if you combine `inviteOnly` with `allowedEmailDomains` (allowed domains already admit invitations), or a restricted policy with the `upgradeAnonymous` plugin (it lets an anonymous user claim any email).
|
|
99
|
+
|
|
100
|
+
Invitation acceptance itself still needs the invitation ID from the email, so knowing an invited address isn't enough to join an organization. Pair a restricted policy with `emailVerification` if accounts must prove their email before use.
|
|
101
|
+
|
|
102
|
+
A per-method hard block is separate: `emailAndPassword.disableSignUp` and the `emailOtp` / `magicLink` `disableSignUp` options refuse new accounts on that method even for invitees.
|
|
103
|
+
|
|
104
|
+
## Account Linking
|
|
105
|
+
|
|
106
|
+
When someone signs in with a social provider and an account with the same email already exists, Better Auth links the two only if the provider verified the email (or is listed as trusted) **and** the existing account's email is verified. The second condition stops a pre-registered, unverified account from absorbing a real owner's Google sign-in. The compiler pins both conditions explicitly, so a future Better Auth default can't loosen them; the local-email condition is not configurable.
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
auth: defineAuth("better-auth", {
|
|
110
|
+
socialProviders: { google: { enabled: true } },
|
|
111
|
+
accountLinking: {
|
|
112
|
+
trustedProviders: ["google"], // trust Google's email even when it says unverified
|
|
113
|
+
// enabled: false, // never link implicitly; users link while signed in
|
|
114
|
+
},
|
|
115
|
+
})
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
`trustedProviders` entries must be enabled `socialProviders`; anything else fails the compile.
|
|
119
|
+
|
|
120
|
+
## Sign-In Tokens at Rest
|
|
121
|
+
|
|
122
|
+
Magic-link tokens and email OTP codes are stored **hashed** in the verification table (`storeToken: "hashed"`, `storeOTP: "hashed"`), so a leaked database row can't be replayed. Both lifetimes are emitted explicitly (default 300 seconds, `plugins.<name>.expiresIn` to change), and the emails state the same value.
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
79
126
|
## Rate Limiting
|
|
80
127
|
|
|
81
128
|
Quickback includes per-IP rate limiting by default to protect against brute-force attacks and abuse.
|
|
@@ -194,25 +241,25 @@ Quickback supports three bearer-token flavors alongside the standard browser ses
|
|
|
194
241
|
| Session cookie | Browser SPAs (CMS, Account, your app) | Better Auth session lookup |
|
|
195
242
|
| Session-token bearer | API clients that grabbed `set-auth-token` | Better Auth `bearer` plugin |
|
|
196
243
|
| JWT bearer | API clients that mint at `GET /auth/v1/token` | In-worker JWT fast-path (no DB hit) |
|
|
197
|
-
| API-key bearer | Long-lived programmatic access | `apiKey` plugin / `x-api-key` header (never a query parameter) |
|
|
244
|
+
| API-key bearer | Long-lived programmatic access | `apiKey` plugin / `x-api-key` header, or a prefixed key as `Authorization: Bearer` (never a query parameter) |
|
|
198
245
|
|
|
199
246
|
These match Better Auth's own framing of bearer tokens as **an alternative to cookies, not a supplement** — a request uses one or the other.
|
|
200
247
|
|
|
201
|
-
###
|
|
248
|
+
### One transport per request
|
|
202
249
|
|
|
203
|
-
|
|
250
|
+
A request carries exactly one credential. Two or more of `Cookie`, `Authorization`, and `x-api-key` is a `400 AUTH_METHOD_CONFLICT` — no precedence rules, no silent override:
|
|
204
251
|
|
|
205
252
|
```
|
|
206
253
|
Request Resolved as
|
|
207
254
|
────────────────────────────────────── ─────────────
|
|
208
255
|
Cookie only cookie session
|
|
209
256
|
Authorization: Bearer <jwt> JWT claims
|
|
210
|
-
Authorization: Bearer <api-key> API-key owner
|
|
211
257
|
Authorization: Bearer <session-token> bearer session
|
|
212
|
-
|
|
258
|
+
x-api-key: <api-key> API-key owner (narrowed by its scopes)
|
|
259
|
+
Any two of the above 400 AUTH_METHOD_CONFLICT
|
|
213
260
|
```
|
|
214
261
|
|
|
215
|
-
This closes a class of silent-impersonation bugs where an ambient session cookie (multi-account browser tabs, a malicious extension, a misconfigured proxy injecting `Set-Cookie`) would otherwise override an explicit
|
|
262
|
+
This closes a class of silent-impersonation bugs where an ambient session cookie (multi-account browser tabs, a malicious extension, a misconfigured proxy injecting `Set-Cookie`) would otherwise override an explicit credential. The decision is made before `getSession()` runs, so it applies to every code path in the auth middleware.
|
|
216
263
|
|
|
217
264
|
The api-key and JWT bearers also short-circuit before cookie resolution via dedicated fast-paths — they never touch the database for session lookup. Only session-token bearers reach `getSession()`, where Better Auth's `bearer` plugin resolves the `Authorization` header.
|
|
218
265
|
|
|
@@ -13,7 +13,7 @@ Better Auth supports multiple sign-in methods:
|
|
|
13
13
|
|
|
14
14
|
## Session Handling
|
|
15
15
|
|
|
16
|
-
Sessions live in the **auth database
|
|
16
|
+
Sessions live in the **auth database**, and every session lookup reads it — the compiler does not configure Better Auth `secondaryStorage`, so a KV namespace does not cache sessions. To take session reads off the database hot path, enable the signed cookie cache (`session.cookieCache`), which trades revocation latency (capped by its `maxAge`) for fewer reads.
|
|
17
17
|
|
|
18
18
|
The generated auth middleware resolves the session once per request and hydrates a single Hono context variable, `ctx` — it does **not** set `session` or `user` variables:
|
|
19
19
|
|
|
@@ -230,6 +230,8 @@ The matching `ws_ticket` issuer is the same one the Broadcaster already uses at
|
|
|
230
230
|
|
|
231
231
|
Drop in [`Y-PartyServer`](https://github.com/cloudflare/partykit) when you need true concurrent text/document editing. It's a `Server` subclass that wraps Yjs's sync protocol; everything else above stays the same.
|
|
232
232
|
|
|
233
|
+
Add `y-partyserver` and `yjs` to `build.dependencies` alongside `partyserver`. The cloud compiler image ships all three — plus `y-prosemirror` and the `prosemirror-*` packages for rich-text docs — so hosted complete compiles can bundle-check the room.
|
|
234
|
+
|
|
233
235
|
```ts
|
|
234
236
|
import { YServer } from 'y-partyserver';
|
|
235
237
|
|
|
@@ -233,6 +233,8 @@ has no effect.
|
|
|
233
233
|
> `readRoles` are applied on every route that can reveal an object — downloads,
|
|
234
234
|
> `GET /object` listings, and `POST /url` lookups alike. Being a member of the
|
|
235
235
|
> owning organization is not sufficient on its own.
|
|
236
|
+
> Downloads and `HEAD` also require a live metadata row for every read scope;
|
|
237
|
+
> soft-deleted objects return `404` even if bytes remain in R2.
|
|
236
238
|
>
|
|
237
239
|
> - **Listing** (`GET /object`) returns only objects in buckets you may read.
|
|
238
240
|
> The filter is applied in the query, so `limit` and `offset` page over your
|
|
@@ -1,45 +1,15 @@
|
|
|
1
1
|
# Using KV
|
|
2
2
|
|
|
3
|
-
Cloudflare KV is
|
|
3
|
+
Cloudflare KV is a namespace your handlers can use for caching. The compiler itself keeps very little in it.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## What the compiler stores in KV
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- **JWT revocation stamps** — with [`auth.jwt.revocationCheck: 'kv'`](/configure/auth) the generated auth writes a timestamp when a user is banned or a membership is removed or changed, and the JWT fast path refuses tokens issued before it.
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
// How sessions work internally (auto-generated)
|
|
11
|
-
// On login: session stored in KV
|
|
12
|
-
await kv.put(`session:${sessionToken}`, JSON.stringify(sessionData), {
|
|
13
|
-
expirationTtl: 60 * 60 * 24 * 7, // 7 days
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
// On each request: session retrieved from KV
|
|
17
|
-
const session = await kv.get(`session:${sessionToken}`, "json");
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
Sessions are automatically:
|
|
21
|
-
- **Created** on sign-in (email/password, passkey, magic link, etc.)
|
|
22
|
-
- **Validated** on every authenticated request via the `Authorization: Bearer <token>` header
|
|
23
|
-
- **Expired** after the configured TTL (default: 7 days)
|
|
24
|
-
- **Deleted** on sign-out
|
|
25
|
-
|
|
26
|
-
## Rate Limiting
|
|
27
|
-
|
|
28
|
-
KV powers the rate limiting middleware that protects auth endpoints:
|
|
29
|
-
|
|
30
|
-
```typescript
|
|
31
|
-
// Rate limit key structure (auto-generated)
|
|
32
|
-
// Key: ratelimit:{ip}:{endpoint}
|
|
33
|
-
// Value: request count
|
|
34
|
-
// TTL: rate limit window (e.g., 60 seconds)
|
|
35
|
-
const key = `ratelimit:${ip}:${endpoint}`;
|
|
36
|
-
const count = await kv.get(key);
|
|
37
|
-
if (count && parseInt(count) > limit) {
|
|
38
|
-
return c.json({ error: "Too many requests" }, 429);
|
|
39
|
-
}
|
|
40
|
-
```
|
|
9
|
+
## What is *not* in KV
|
|
41
10
|
|
|
42
|
-
|
|
11
|
+
- **Sessions** live in the auth database. The compiler does not configure Better Auth `secondaryStorage`; see [Session Handling](/platform/auth/using-auth#session-handling).
|
|
12
|
+
- **Auth rate-limit counters** live in the auth database on Cloudflare (`rateLimit.storage: "database"`, the default there). See [Auth Security](/platform/auth/security#counter-storage).
|
|
43
13
|
|
|
44
14
|
## Caching
|
|
45
15
|
|
|
@@ -376,7 +376,8 @@ export default defineAction({
|
|
|
376
376
|
|
|
377
377
|
// ctx.crypto is hydrated for authenticated requests only — a PUBLIC
|
|
378
378
|
// action reads an .encrypted() column through decryptValue directly.
|
|
379
|
-
const secret = await decryptValue(env, unsafeDb, conn.organizationId, conn.signingSecret
|
|
379
|
+
const secret = await decryptValue(env, unsafeDb, conn.organizationId, conn.signingSecret,
|
|
380
|
+
{ table: "connections", column: "signingSecret" });
|
|
380
381
|
// verify `rawBody` + the provider's signature headers with `secret`;
|
|
381
382
|
// throw a 401 ActionError on failure — BEFORE touching any tenant data.
|
|
382
383
|
|
|
@@ -35,6 +35,10 @@ The `/compile` endpoint requires either a session token (from `quickback login`)
|
|
|
35
35
|
|
|
36
36
|
The map uses project-root-relative paths and follows the same layout `quickback build` reads from disk: `quickback/quickback.config.ts`, `quickback/features/**`, `quickback/services/**`, `quickback/{lib,hooks,plugins,middlewares,email-templates}/**`, plus `quickback/drizzle/**/meta/**` and `wrangler.toml` for incremental builds.
|
|
37
37
|
|
|
38
|
+
Raw-files requests may contain at most 30,000 paths, with at most 32 path
|
|
39
|
+
segments per entry. Both compiler backends reject larger maps before organizing
|
|
40
|
+
the project.
|
|
41
|
+
|
|
38
42
|
Three constraints, all fail-closed:
|
|
39
43
|
|
|
40
44
|
- **The config must be fully static.** The compiler parses `quickback.config.ts` with a literals-only evaluator — it never executes user code. Object/array/string/number/boolean literals, substitution-free template literals, and the `define*` helper calls all work; variables, computed values, and imports-as-values are rejected with a 400 that names the offending construct and line.
|
|
@@ -150,18 +150,22 @@ reaches Wrangler first, apply the same fix above and rebuild Generated Backend
|
|
|
150
150
|
before Deploy.
|
|
151
151
|
|
|
152
152
|
The compile sandbox has no network and bundles against the compiler image's
|
|
153
|
-
own dependencies
|
|
154
|
-
[`build.dependencies`](/configure#custom-dependencies)
|
|
155
|
-
|
|
156
|
-
bundle check for those projects and says so in the compile warnings:
|
|
153
|
+
own dependencies. A dependency declared in
|
|
154
|
+
[`build.dependencies`](/configure#custom-dependencies) may not be available
|
|
155
|
+
there. In that case, a hosted complete compile fails before the bundle check:
|
|
157
156
|
|
|
158
157
|
```
|
|
159
|
-
|
|
160
|
-
compiler image:
|
|
158
|
+
Worker bundle check cannot run: build.dependencies not installed in the
|
|
159
|
+
compiler image: fast-xml-parser
|
|
161
160
|
```
|
|
162
161
|
|
|
163
|
-
The
|
|
164
|
-
|
|
162
|
+
The image preinstalls a set of [supported build
|
|
163
|
+
dependencies](/configure#custom-dependencies) — PartyServer, Yjs,
|
|
164
|
+
ProseMirror, `drizzle-zod`, and React Email among them. Type-only `@types/*`
|
|
165
|
+
packages never block the check. For any other package, build locally with it
|
|
166
|
+
installed or request that it be added to the compiler image. Validation
|
|
167
|
+
compiles (`complete=false`) still generate output without running the Worker
|
|
168
|
+
bundle check.
|
|
165
169
|
|
|
166
170
|
Store the Better Auth id as plain text:
|
|
167
171
|
|
|
@@ -9,11 +9,12 @@ API keys are a user credential. Manage them at `/api-keys`, linked from `/profil
|
|
|
9
9
|
- Scoped to an organization via `metadata.organizationId` so the key inherits your role in that tenant
|
|
10
10
|
- One organization: stamped automatically
|
|
11
11
|
- Several organizations: pick one when creating
|
|
12
|
+
- Optional **Scopes** — space-separated `read`, `write`, `<resource>:read`, `<resource>:write`. Empty means full access as your role; scopes only narrow it. Unknown scopes are rejected. See [Scopes](/platform/auth/api-keys#scopes)
|
|
12
13
|
|
|
13
14
|
## Managing Keys
|
|
14
15
|
|
|
15
16
|
- List every key you own (not filtered to the current org)
|
|
16
|
-
- See last-used timestamp
|
|
17
|
+
- See last-used timestamp, which organization the key is scoped to, and its scopes
|
|
17
18
|
- Revoke individual keys
|
|
18
19
|
|
|
19
20
|
`/$slug/api-keys` redirects here so old bookmarks still work.
|
|
@@ -355,14 +355,15 @@ Full-featured SaaS with organizations, teams, and admin panel.
|
|
|
355
355
|
|
|
356
356
|
### Invite-Only Platform
|
|
357
357
|
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
358
|
+
Set it on the server, not with a `VITE_*` flag — a flag only hides the signup screen:
|
|
359
|
+
|
|
360
|
+
```ts
|
|
361
|
+
account: {
|
|
362
|
+
auth: { signup: false, passkey: true, organizations: true, admin: true },
|
|
363
|
+
},
|
|
363
364
|
```
|
|
364
365
|
|
|
365
|
-
|
|
366
|
+
`account.auth.signup: false` sets [`signup.inviteOnly`](/platform/auth/security#signup-policy): only admin-created accounts and emails with a pending organization invitation can create an account, on every sign-in method. The SPA hides open signup; an invitee's invitation link still reaches `/signup`.
|
|
366
367
|
|
|
367
368
|
## Feature Detection
|
|
368
369
|
|
|
@@ -14,7 +14,7 @@ The sign-in email contains the six-digit code only — no magic-link companion.
|
|
|
14
14
|
|
|
15
15
|
## What about magic links?
|
|
16
16
|
|
|
17
|
-
Account UI does not
|
|
17
|
+
Account UI's sign-in screen does not request magic links — its passwordless flow is OTP. When the `magicLink` Better Auth plugin is enabled (see [Auth Plugins](/platform/auth/plugins#magic-links)) and your own UI requests a link, the emailed link opens Account UI's `/magic-link` page. Only the **Continue signing in** button there spends the single-use token, so a mail scanner that fetches the link can't burn it.
|
|
18
18
|
|
|
19
19
|
## Related
|
|
20
20
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Auth Hooks
|
|
2
2
|
|
|
3
|
-
Quickback discovers project-level auth hooks at `quickback/hooks/`. Most `before-`/`after-` lifecycle hooks wire directly into [Better Auth's `databaseHooks`](https://www.better-auth.com/docs/concepts/database#database-hooks); `before-email-otp-activate.ts` is a narrower compiler-owned atomic ceremony, and the `resolve-*` hooks are trusted server resolvers called from generated middleware (OAuth) or the email send. Use them for post-signup bootstrap, signup gating, tenant resolution, and per-recipient email context.
|
|
3
|
+
Quickback discovers project-level auth hooks at `quickback/hooks/`. Most `before-`/`after-` lifecycle hooks wire directly into [Better Auth's `databaseHooks`](https://www.better-auth.com/docs/concepts/database#database-hooks); `before-email-otp-activate.ts` is a narrower compiler-owned atomic ceremony, and the `resolve-*` hooks are trusted server resolvers called from generated middleware (OAuth) or the email send. `before-invitation-create.ts` is the organization plugin's own `beforeCreateInvitation` hook. Use them for post-signup bootstrap, signup gating, tenant resolution, and per-recipient email context.
|
|
4
4
|
|
|
5
5
|
The classic case is multi-tenant: when `account.auth.organizations: true` is set, a freshly signed-up user has no `activeOrganizationId`, so every authenticated `/api/v1/*` returns `403 ORG_REQUIRED`. An `after-user-create` hook can auto-provision a personal workspace + member row so the next request just works.
|
|
6
6
|
|
|
@@ -14,6 +14,7 @@ quickback/
|
|
|
14
14
|
before-email-otp-activate.ts
|
|
15
15
|
after-session-create.ts
|
|
16
16
|
after-admin-user-create.ts
|
|
17
|
+
before-invitation-create.ts
|
|
17
18
|
resolve-oauth-context.ts
|
|
18
19
|
resolve-email-context.ts
|
|
19
20
|
```
|
|
@@ -29,6 +30,7 @@ Each file has a single default export — an `async (entity, ctx) => ...` functi
|
|
|
29
30
|
| `before-email-otp-activate.ts` | Atomic email-OTP activation before `user.update` | `{ userId, email, user }` | `void \| false` |
|
|
30
31
|
| `after-session-create.ts` | `databaseHooks.session.create.after` | `Session` | `void` |
|
|
31
32
|
| `after-admin-user-create.ts` | `databaseHooks.user.create.after` (filtered) | `User` | `void` |
|
|
33
|
+
| `before-invitation-create.ts` | `organizationHooks.beforeCreateInvitation` | `{ invitation, inviter, organization }` | `void \| { data?: Partial<Invitation> }` |
|
|
32
34
|
| `resolve-oauth-context.ts` | OAuth bearer middleware | OAuth identity + session | Partial `AppContext` tenant fields |
|
|
33
35
|
| `resolve-email-context.ts` | emailOTP `sendVerificationOTP` | `{ email, type, name }` | Extra fields merged into the email template context |
|
|
34
36
|
|
|
@@ -201,6 +203,51 @@ Notes:
|
|
|
201
203
|
- This is **not** a Better Auth `databaseHook` — it's consumed only by the
|
|
202
204
|
emailOTP send, so it adds no signup/session latency.
|
|
203
205
|
|
|
206
|
+
## Gate or reroute an organization invitation
|
|
207
|
+
|
|
208
|
+
`POST /auth/v1/organization/invite-member` sends mail to whatever address the
|
|
209
|
+
caller types, from generated code — a sandbox or demo plan that contains every
|
|
210
|
+
other send through a policy cannot reach it. Add
|
|
211
|
+
`quickback/hooks/before-invitation-create.ts` and the compiler wires it as the
|
|
212
|
+
organization plugin's `organizationHooks.beforeCreateInvitation`. Throw to
|
|
213
|
+
abort; return `{ data: { email } }` to redirect the recipient. Better Auth
|
|
214
|
+
merges `data` onto the invitation row, so any invitation field (`role`,
|
|
215
|
+
`expiresAt`, …) can be overridden the same way.
|
|
216
|
+
|
|
217
|
+
```ts title="quickback/hooks/before-invitation-create.ts"
|
|
218
|
+
import { APIError } from "better-auth/api";
|
|
219
|
+
import { eq } from "drizzle-orm";
|
|
220
|
+
|
|
221
|
+
export default async ({ invitation, inviter, organization }, { authDb, authSchema }) => {
|
|
222
|
+
const [plan] = await authDb
|
|
223
|
+
.select({ policy: authSchema.organization.metadata })
|
|
224
|
+
.from(authSchema.organization)
|
|
225
|
+
.where(eq(authSchema.organization.id, organization.id))
|
|
226
|
+
.limit(1);
|
|
227
|
+
|
|
228
|
+
if (plan?.policy === "sandbox") {
|
|
229
|
+
throw new APIError("FORBIDDEN", { message: "Sandbox organizations cannot invite members." });
|
|
230
|
+
}
|
|
231
|
+
if (plan?.policy === "redirect") {
|
|
232
|
+
// Deliver every invite to the org owner instead of the typed address.
|
|
233
|
+
return { data: { email: inviter.email } };
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
Notes:
|
|
239
|
+
|
|
240
|
+
- **Not a `databaseHook`.** It runs inside the organization plugin, before the
|
|
241
|
+
invitation row is written and before `sendInvitationEmail`. `ctx` is the
|
|
242
|
+
standard [hook ctx](#ctx-shape) minus `baContext`.
|
|
243
|
+
- **The seat cap runs first.** With the
|
|
244
|
+
[subscriptions plugin](/platform/auth/plugins/subscriptions), a full plan
|
|
245
|
+
refuses the invite before your hook is called.
|
|
246
|
+
- **`invitationLimit` is a config option, not a hook.** Better Auth's cap on
|
|
247
|
+
pending invitations per organization passes straight through
|
|
248
|
+
`plugins.organization` — see [Better Auth plugins](/configure/providers#better-auth-plugins).
|
|
249
|
+
- Requires the organization plugin; the file is a compile error without it.
|
|
250
|
+
|
|
204
251
|
## ctx shape
|
|
205
252
|
|
|
206
253
|
Every hook receives `(entity, ctx)`:
|
|
@@ -259,6 +306,7 @@ What happens when a hook throws is the #1 thing that bites people:
|
|
|
259
306
|
| `before-email-otp-activate` | The entire atomic ceremony rolls back: OTP consumption, hook writes, verification update, and session insert. |
|
|
260
307
|
| `after-user-create` | The user **is** created (the BA insert already committed). Any derived rows your hook started writing become orphans. |
|
|
261
308
|
| `after-session-create`| Same as above — the session row exists; partial writes leak. |
|
|
309
|
+
| `before-invitation-create` | The invitation is **not** created and no email is sent. Throw Better Auth's `APIError` for a clean 4xx. |
|
|
262
310
|
|
|
263
311
|
For `after-*` hooks, design for **idempotency**: use the entity's `id` as a stable seed for any derived rows so re-running the hook (manually or via a background reconciler) is safe. Don't generate fresh `cuid()`s for derived rows you'd want to recover.
|
|
264
312
|
|
|
@@ -332,7 +380,7 @@ export default async (newSession, { authDb, authSchema }) => {
|
|
|
332
380
|
|
|
333
381
|
### Normalize and gate signup
|
|
334
382
|
|
|
335
|
-
`before-*` hooks can return `{ data: Partial<User> }` to mutate the row before insert. Throw to abort.
|
|
383
|
+
`before-*` hooks can return `{ data: Partial<User> }` to mutate the row before insert. Throw to abort. For invite-only or allowed-domain signup, use the built-in [signup policy](/platform/auth/security#signup-policy) instead — it runs before this hook on every sign-in method.
|
|
336
384
|
|
|
337
385
|
```ts title="quickback/hooks/before-user-create.ts"
|
|
338
386
|
export default async (user: { email: string; name?: string }) => {
|