@quickback-dev/cli 0.18.0 → 0.31.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.
Files changed (72) hide show
  1. package/dist/commands/compile.d.ts.map +1 -1
  2. package/dist/commands/compile.js +17 -1
  3. package/dist/commands/compile.js.map +1 -1
  4. package/dist/docs/content.d.ts.map +1 -1
  5. package/dist/docs/content.js +23 -58
  6. package/dist/docs/content.js.map +1 -1
  7. package/dist/index.js +1 -1
  8. package/dist/lib/api-client.d.ts +17 -0
  9. package/dist/lib/api-client.d.ts.map +1 -1
  10. package/dist/lib/api-client.js.map +1 -1
  11. package/dist/lib/file-loader.d.ts +24 -0
  12. package/dist/lib/file-loader.d.ts.map +1 -1
  13. package/dist/lib/file-loader.js +46 -0
  14. package/dist/lib/file-loader.js.map +1 -1
  15. package/dist/skill/docs/changelog.md +423 -1
  16. package/dist/skill/docs/compiler/config/domains.md +44 -10
  17. package/dist/skill/docs/compiler/config/output.md +1 -1
  18. package/dist/skill/docs/compiler/config/providers.md +6 -12
  19. package/dist/skill/docs/compiler/config/variables.md +0 -30
  20. package/dist/skill/docs/compiler/definitions/access.md +203 -1
  21. package/dist/skill/docs/compiler/definitions/actions.md +40 -7
  22. package/dist/skill/docs/compiler/definitions/schema.md +6 -10
  23. package/dist/skill/docs/compiler/index.md +15 -34
  24. package/dist/skill/docs/compiler/targets/hono-api/cloudflare.md +1 -2
  25. package/dist/skill/docs/compiler/targets/hono-api/database/neon.md +0 -1
  26. package/dist/skill/docs/compiler/targets/hono-api/using-the-api/actions-api.md +19 -0
  27. package/dist/skill/docs/compiler/targets/hono-api/using-the-api/batch-operations.md +1 -1
  28. package/dist/skill/docs/compiler/targets/index.md +6 -34
  29. package/dist/skill/docs/index.md +2 -5
  30. package/dist/skill/docs/stack/account-ui/customization.md +2 -14
  31. package/dist/skill/docs/stack/account-ui/environment-variables.md +7 -1
  32. package/dist/skill/docs/stack/account-ui/features/avatars.md +2 -4
  33. package/dist/skill/docs/stack/account-ui/features/index.md +1 -1
  34. package/dist/skill/docs/stack/account-ui/features/organizations.md +31 -11
  35. package/dist/skill/docs/stack/account-ui/index.md +5 -43
  36. package/dist/skill/docs/stack/account-ui/with-quickback.md +2 -75
  37. package/dist/skill/docs/stack/auth/plugins/index.md +74 -0
  38. package/package.json +1 -1
  39. package/src/skill/docs/changelog.md +362 -0
  40. package/src/skill/docs/compiler/config/providers.md +6 -12
  41. package/src/skill/docs/compiler/config/variables.md +0 -30
  42. package/src/skill/docs/compiler/definitions/access.md +203 -1
  43. package/src/skill/docs/compiler/definitions/actions.md +40 -7
  44. package/src/skill/docs/compiler/definitions/schema.md +6 -10
  45. package/src/skill/docs/compiler/index.md +15 -34
  46. package/src/skill/docs/compiler/targets/hono-api/cloudflare.md +1 -2
  47. package/src/skill/docs/compiler/targets/hono-api/database/neon.md +0 -1
  48. package/src/skill/docs/compiler/targets/hono-api/using-the-api/actions-api.md +19 -0
  49. package/src/skill/docs/compiler/targets/hono-api/using-the-api/batch-operations.md +1 -1
  50. package/src/skill/docs/compiler/targets/index.md +6 -34
  51. package/src/skill/docs/index.md +2 -5
  52. package/src/skill/docs/stack/account-ui/customization.md +2 -14
  53. package/src/skill/docs/stack/account-ui/environment-variables.md +7 -1
  54. package/src/skill/docs/stack/account-ui/features/avatars.md +2 -4
  55. package/src/skill/docs/stack/account-ui/features/index.md +1 -1
  56. package/src/skill/docs/stack/account-ui/features/organizations.md +31 -11
  57. package/src/skill/docs/stack/account-ui/index.md +5 -43
  58. package/src/skill/docs/stack/account-ui/with-quickback.md +2 -75
  59. package/dist/skill/docs/compiler/targets/supabase-rls/index.md +0 -55
  60. package/dist/skill/docs/compiler/targets/supabase-rls/limitations.md +0 -48
  61. package/dist/skill/docs/compiler/targets/supabase-rls/mappings.md +0 -99
  62. package/dist/skill/docs/compiler/targets/supabase-rls/setup.md +0 -88
  63. package/dist/skill/docs/stack/account-ui/library-usage.md +0 -257
  64. package/dist/skill/docs/stack/account-ui/standalone.md +0 -149
  65. package/dist/skill/docs/stack/account-ui/worker.md +0 -362
  66. package/src/skill/docs/compiler/targets/supabase-rls/index.md +0 -55
  67. package/src/skill/docs/compiler/targets/supabase-rls/limitations.md +0 -48
  68. package/src/skill/docs/compiler/targets/supabase-rls/mappings.md +0 -99
  69. package/src/skill/docs/compiler/targets/supabase-rls/setup.md +0 -88
  70. package/src/skill/docs/stack/account-ui/library-usage.md +0 -257
  71. package/src/skill/docs/stack/account-ui/standalone.md +0 -149
  72. package/src/skill/docs/stack/account-ui/worker.md +0 -362
@@ -288,4 +288,4 @@ DISABLE_EMAIL_STATUS_CHECK=true # Allow test emails
288
288
 
289
289
  - **[Environment Variables](/stack/account-ui/environment-variables)** - Complete variable reference
290
290
  - **[Customization](/stack/account-ui/customization)** - Customize UI text and labels
291
- - **[Worker Setup](/stack/account-ui/worker)** - Deploy your configuration
291
+ - **[With Quickback](/stack/account-ui/with-quickback)** - How the compiler builds Account UI into your Worker
@@ -1,27 +1,47 @@
1
1
  # Organizations
2
2
 
3
- Account UI provides a complete organization management interface when `ENABLE_ORGANIZATIONS=true`.
3
+ Account UI provides a complete organization management interface when `VITE_ENABLE_ORGANIZATIONS=true`. Teams are a separate opt-in (`VITE_ENABLE_ORG_TEAMS`), surfaced when the compiler detects `organization({ teams: { enabled: true } })` in the Better Auth config.
4
4
 
5
5
  ## Organization CRUD
6
6
 
7
- - Create new organizations
8
- - Update organization name and settings
9
- - Delete organizations (owner only)
7
+ - Create new organizations, with `checkSlug` debounce on the slug field
8
+ - Update name, **slug** (rename navigates to the new URL), **metadata** (JSON object), and logo
9
+ - Delete organizations — gated on the `organization:delete` permission (default: owner)
10
10
 
11
11
  ## Member Management
12
12
 
13
- - Invite members by email
13
+ - Invite members by email (with an optional team picker when teams are enabled)
14
14
  - Assign roles: **owner**, **admin**, **member**
15
- - Remove members
16
- - Transfer ownership
15
+ - Change roles and remove members — actions are filtered per-target by the role hierarchy (non-owners can't manage owner-role members)
16
+ - Leave the organization
17
+
18
+ > **Note:** These three roles (`owner`, `admin`, `member`) are Better Auth's built-in organization roles and map directly to Account UI's role picker. Use the same roles in your Quickback [Access](/compiler/definitions/access) rules — with [`auth.roleHierarchy`](/compiler/definitions/access#role-hierarchy) configured, you can write `roles: ["member+"]` to mean "member and above."
17
19
 
18
20
  ## Invitations
19
21
 
20
- - Pending invitation list
21
- - Resend invitations
22
- - Cancel invitations
22
+ - Pending invitation list, per organization
23
+ - Resend, cancel (per-org), accept, and reject (per-user)
24
+ - Pending invites across organizations land on the user's `/dashboard`
25
+ - Invitations carry an optional `teamId` when teams are enabled — the invitee joins that team on accept
23
26
 
24
- > **Note:** These three roles (`owner`, `admin`, `member`) are Better Auth's built-in organization roles and map directly to Account UI's role picker. Use the same roles in your Quickback [Access](/compiler/definitions/access) rules — with [`auth.roleHierarchy`](/compiler/definitions/access#role-hierarchy) configured, you can write `roles: ["member+"]` to mean "member and above."
27
+ ## Teams
28
+
29
+ Set `organization({ teams: { enabled: true } })` in your Better Auth config. The compiler emits `VITE_ENABLE_ORG_TEAMS=true` and the SPA exposes:
30
+
31
+ - **Teams tab** on each organization, split into "Your teams" and "Other teams"
32
+ - **Team detail** page with member roster, add/remove members
33
+ - **Active-team picker** in the organization header — switches `session.activeTeamId` via `setActiveTeam`, so server-side handlers can scope by team
34
+ - **Team-aware invitations** — when sending an invite, optionally pick a team; the member is added on accept
35
+
36
+ Per-team actions (create / rename / delete / add-member / remove-member) gate on the `team:create`, `team:update`, and `team:delete` permissions from Better Auth's default statements.
37
+
38
+ ## Permission-aware UI
39
+
40
+ Account UI uses Better Auth's `checkRolePermission` API instead of hardcoded role checks. The `OrganizationContext` exposes a `can(resource, action)` helper that handles the default statements (`organization`, `member`, `invitation`, `team`, `ac`) and respects any custom roles you've registered via the BA `ac` option.
41
+
42
+ Multi-role users — Better Auth stores multiple roles as a comma-separated string — are handled by checking each role independently; the action is allowed if any one of them grants it.
43
+
44
+ This means projects that ship custom roles get a UI that matches what their server actually authorizes, without modifying the Account SPA.
25
45
 
26
46
  ## Related
27
47
 
@@ -1,6 +1,6 @@
1
1
  # Quickback Account UI
2
2
 
3
- A complete authentication and account management frontend. It handles login, signup, password reset, profile management, device sessions, passkeys, organizations, and admin — so you don't have to build any of it.
3
+ A complete authentication and account management frontend that ships with the Quickback Stack. It handles login, signup, password reset, profile management, device sessions, passkeys, organizations, and admin — so you don't have to build any of it.
4
4
 
5
5
  ## What's Included
6
6
 
@@ -20,9 +20,9 @@ Dashboard with org switching, org creation, member invitations, role management,
20
20
 
21
21
  User management dashboard — view all users, search, create accounts, ban/unban, reset passwords, and manage sessions. Only accessible to users with the `admin` role. Can be served on its own domain (e.g., `admin.example.com`) via the `adminDomain` config.
22
22
 
23
- ## Quick Start (Compiler-Embedded)
23
+ ## How to Enable
24
24
 
25
- The recommended approach: add `account` to your `quickback.config.ts` and compile. The compiler builds the SPA from source with your project-specific settings baked in.
25
+ Add `account` to your `quickback.config.ts` and compile. The compiler builds the SPA from source with your project-specific settings baked in and bundles it into your Worker.
26
26
 
27
27
  ```typescript title="quickback/quickback.config.ts"
28
28
  export default {
@@ -53,7 +53,7 @@ That's it. The compiler:
53
53
  2. Generates a `.env` file with the correct `VITE_*` variables
54
54
  3. Builds the SPA from source with Vite (inside Docker)
55
55
  4. Excludes routes for disabled features (compile-time tree shaking)
56
- 5. Outputs the built assets alongside your API code
56
+ 5. Bundles the built assets into your Worker alongside the API
57
57
 
58
58
  No manual `.env` configuration needed. No separate deployment.
59
59
 
@@ -91,42 +91,6 @@ Auth feature flags control which pages are included in the bundle:
91
91
 
92
92
  When a flag is `false`, the corresponding route files are **removed before the Vite build** — they never appear in the JavaScript bundle. This keeps production bundles minimal.
93
93
 
94
- ## Standalone Usage
95
-
96
- Account UI also works outside of Quickback:
97
-
98
- ### Template (own the source)
99
-
100
- Clone the repo and customize directly:
101
-
102
- ```bash
103
- npx degit Kardoe-com/quickback-better-auth-account-ui my-account-app
104
- cd my-account-app
105
- npm install
106
- ```
107
-
108
- Configure via `.env` files and deploy as a standalone Cloudflare Worker. See [Standalone Usage](/stack/account-ui/standalone) for Better Auth backends or [With Quickback](/stack/account-ui/with-quickback) for Quickback-compiled backends.
109
-
110
- ### Library (npm package)
111
-
112
- Install as a dependency:
113
-
114
- ```bash
115
- npm install quickback-better-auth-account-ui
116
- ```
117
-
118
- ```tsx
119
- import { AuthApp, setAppConfig } from 'quickback-better-auth-account-ui';
120
- import 'quickback-better-auth-account-ui/styles.css';
121
-
122
- setAppConfig({
123
- authRoute: 'quickback',
124
- name: 'My App',
125
- });
126
- ```
127
-
128
- See [Library Usage](/stack/account-ui/library-usage) for details.
129
-
130
94
  ## Features
131
95
 
132
96
  - **Authentication** — Email/password, passkeys (WebAuthn), email OTP, magic links, email verification, password reset
@@ -138,9 +102,7 @@ See [Library Usage](/stack/account-ui/library-usage) for details.
138
102
 
139
103
  ## Next Steps
140
104
 
141
- - **[With Quickback](/stack/account-ui/with-quickback)** — Compiler-embedded and standalone setup
142
- - **[Standalone Usage](/stack/account-ui/standalone)** — Use with any Better Auth backend
143
- - **[Library Usage](/stack/account-ui/library-usage)** — Import as an npm package
105
+ - **[With Quickback](/stack/account-ui/with-quickback)** — Configuration reference for the `account` block
144
106
  - **[Feature Flags](/stack/account-ui/features)** — Enable and disable features
145
107
  - **[Environment Variables](/stack/account-ui/environment-variables)** — Configuration reference
146
108
  - **[Customization](/stack/account-ui/customization)** — Branding, labels, and theming
@@ -1,8 +1,8 @@
1
1
  # With Quickback
2
2
 
3
- When using Account UI with a Quickback-compiled backend, the recommended approach is to let the compiler build and embed the SPA directly into your Worker.
3
+ Account UI is part of the Quickback Stack. The compiler builds it from source and bundles it into your Worker — there is no separate npm package or standalone deploy path.
4
4
 
5
- ## Compiler-Embedded (Recommended)
5
+ ## Compiler-Embedded
6
6
 
7
7
  Add `account` to your `quickback.config.ts`:
8
8
 
@@ -77,79 +77,6 @@ auth: {
77
77
 
78
78
  Disabled features are excluded at compile time — their route files are removed before the Vite build. See [Configuration](/compiler/config) for all options.
79
79
 
80
- ## Manual Deployment
81
-
82
- If you need Account UI as a separate Worker (not embedded in the API Worker), you can deploy it standalone.
83
-
84
- ### 1. Clone the Template
85
-
86
- ```bash
87
- npx degit Kardoe-com/quickback-better-auth-account-ui my-account-app
88
- cd my-account-app
89
- npm install
90
- ```
91
-
92
- ### 2. Configure for Quickback
93
-
94
- Set the auth route mode to `quickback` to match Quickback's API paths:
95
-
96
- ```bash title=".env"
97
- VITE_AUTH_ROUTE=quickback
98
- # One variable points at the Quickback origin — API, Account, and CMS are all derived from it.
99
- VITE_QUICKBACK_URL=https://secure.example.com
100
- VITE_ACCOUNT_APP_URL=https://account.example.com
101
- VITE_QUICKBACK_APP_URL=https://app.example.com
102
- ```
103
-
104
- In Quickback mode, Account UI routes requests to three API paths:
105
-
106
- | Path | Purpose | Examples |
107
- |------|---------|---------|
108
- | `/auth/v1/*` | Authentication | Login, signup, sessions, passkeys |
109
- | `/api/v1/*` | Data API | Organizations, API keys |
110
- | `/storage/v1/*` | File storage | Avatar uploads, file management |
111
-
112
- ### 3. Configure Features
113
-
114
- Match your `quickback.config.ts` plugins:
115
-
116
- ```bash title=".env"
117
- VITE_APP_NAME=My App
118
- VITE_APP_TAGLINE=Build faster, ship sooner
119
- ENABLE_SIGNUP=true
120
- ENABLE_ORGANIZATIONS=true
121
- ENABLE_PASSKEY=true
122
- ENABLE_ADMIN=true
123
- ```
124
-
125
- ### 4. Build and Deploy
126
-
127
- ```bash
128
- npm run build
129
- npx wrangler deploy
130
- ```
131
-
132
- ## Library Mode
133
-
134
- Install as a dependency instead of cloning:
135
-
136
- ```bash
137
- npm install quickback-better-auth-account-ui
138
- ```
139
-
140
- ```tsx
141
- import { AuthApp, setAppConfig } from 'quickback-better-auth-account-ui';
142
- import 'quickback-better-auth-account-ui/styles.css';
143
-
144
- setAppConfig({
145
- authRoute: 'quickback',
146
- name: 'My App',
147
- companyName: 'My Company',
148
- });
149
- ```
150
-
151
- See [Library Usage](/stack/account-ui/library-usage) for the complete guide.
152
-
153
80
  ## Next Steps
154
81
 
155
82
  - [Configuration](/compiler/config) — CMS and Account config reference
@@ -1,55 +0,0 @@
1
- # Quickback for Supabase RLS
2
-
3
- **Quickback for Supabase RLS** compiles the same `defineTable()` definitions into PostgreSQL Row Level Security policies for Supabase. You keep Supabase Auth, Storage, and Realtime — Quickback adds the database-level security layer.
4
-
5
- ## Who this is for
6
-
7
- You're already on Supabase (or want to be) and you want:
8
-
9
- - **Database-level security** — RLS policies enforced even if a service role key leaks
10
- - **A type-safe DSL** — write security rules in TypeScript, compile to SQL
11
- - **One source of truth** — the same `firewall` and `access` config that powers a Quickback Hono API also generates RLS policies
12
-
13
- What you don't get from this target: generated API routes, batch endpoints, OpenAPI spec, MCP server. Those live with [Quickback for Hono API](/compiler/targets/hono-api). For Supabase you bring your own application code (PostgREST, Edge Functions, or your own server) and the RLS policies enforce security beneath it.
14
-
15
- ## What compiles to RLS
16
-
17
- | Definition | Compiles to |
18
- |------------|-------------|
19
- | `defineTable({ schema })` | `CREATE TABLE` + Drizzle schema |
20
- | `firewall: [...]` | `FOR ALL USING` policies (data isolation) |
21
- | `access.roles: [...]` | `FOR SELECT/INSERT/UPDATE/DELETE USING` policies (role checks) |
22
- | `defineActions()` | **Not compiled** — implement in Edge Functions or your app |
23
- | `views` | **Not compiled** — use Postgres views or column lists |
24
- | `masking` | **Not compiled** — runtime concern, handle in app code |
25
- | `guards` | **Not compiled** — runtime concern, handle in app code |
26
-
27
- See [Mappings](/compiler/targets/supabase-rls/mappings) for full examples and [Limitations](/compiler/targets/supabase-rls/limitations) for what to handle in app code.
28
-
29
- ## Quick start
30
-
31
- ```typescript title="quickback/quickback.config.ts"
32
- import { defineConfig, defineRuntime, defineDatabase, defineAuth } from "@quickback/compiler";
33
-
34
- export default defineConfig({
35
- name: "my-app",
36
- providers: {
37
- runtime: defineRuntime("supabase"),
38
- database: defineDatabase("supabase"),
39
- auth: defineAuth("supabase-auth"),
40
- },
41
- });
42
- ```
43
-
44
- ```bash
45
- quickback compile
46
- supabase db push
47
- ```
48
-
49
- The compiler emits RLS migrations under `supabase/migrations/`. See [Setup](/compiler/targets/supabase-rls/setup) for the full flow.
50
-
51
- ## In this section
52
-
53
- - **[Setup](/compiler/targets/supabase-rls/setup)** — Configure the target, compile, apply migrations
54
- - **[Mappings](/compiler/targets/supabase-rls/mappings)** — Which definitions become which RLS policies
55
- - **[Limitations](/compiler/targets/supabase-rls/limitations)** — What doesn't compile and how to handle it
@@ -1,48 +0,0 @@
1
- # Limitations
2
-
3
- The Supabase target compiles **schema, firewall, and access** to RLS. The other Quickback primitives are runtime concerns that RLS can't express. This page lists what doesn't compile and where to handle it.
4
-
5
- ## Actions
6
-
7
- `defineActions()` describes custom endpoints with input validation, role checks, and side effects. RLS only governs row access, not arbitrary procedures.
8
-
9
- **Where to handle them:**
10
-
11
- - **Supabase Edge Functions** — port the action body to a TypeScript Deno function. Role checks happen in the function; the underlying database mutations still pass through your RLS policies.
12
- - **Postgres functions** — for simple state transitions, write a `CREATE FUNCTION` and call it via `supabase.rpc()`. Use `SECURITY INVOKER` (the default) so RLS still applies.
13
- - **Your application server** — any backend you already run can host the action, with the JWT forwarded to Supabase for the underlying writes.
14
-
15
- ## Views
16
-
17
- Quickback `views` define column-level projections per role (e.g. "members see name + email; admins also see salary"). RLS gates rows, not columns.
18
-
19
- **Where to handle them:**
20
-
21
- - **Postgres views** — `CREATE VIEW` with `SELECT` lists matching each Quickback view. Apply RLS to the view or the underlying table.
22
- - **Column lists in queries** — pass the projection at the application layer: `supabase.from('users').select('id, name, email')`.
23
- - **Column-level grants** — `GRANT SELECT (col1, col2) ON table TO role` for fine-grained server-side restriction.
24
-
25
- ## Masking
26
-
27
- Masking redacts sensitive fields per role at response time (email → `j***@example.com`, SSN → `***-**-1234`). This is purely a runtime transformation — the data is in the row, RLS just decides whether the row is returned.
28
-
29
- **Where to handle it:**
30
-
31
- - **Edge Functions or your server** — apply the mask in the layer that serializes the response.
32
- - **Postgres functions** — for SQL-driven masking, write a wrapper view or function that applies the mask conditionally on `auth.jwt() ->> 'role'`.
33
-
34
- ## Guards
35
-
36
- `guards` block field modifications based on row state, role, or external context (e.g. "members can change `notes` but not `status`; only admins can set `archived`"). Some of this can be expressed with RLS `WITH CHECK`, but the full Quickback guard model is richer than RLS supports.
37
-
38
- **Where to handle them:**
39
-
40
- - **`WITH CHECK` clauses** — simple field-level guards (e.g. "only admins can set `archived = true`") can sometimes be expressed via more granular `FOR UPDATE` policies.
41
- - **Triggers** — `BEFORE UPDATE` triggers can `RAISE EXCEPTION` if a guarded field is modified by a non-eligible role.
42
- - **Edge Functions / app server** — for anything stateful or context-dependent, validate guards in the layer that issues the update.
43
-
44
- ## Generated API routes, batch ops, OpenAPI, MCP
45
-
46
- These are Hono-target features. The Supabase target doesn't generate application code — your app talks to Supabase directly (PostgREST, Edge Functions, or your own server).
47
-
48
- If you want generated routes alongside RLS, consider compiling to the [Hono target with Neon](/compiler/targets/hono-api/database/neon), which gives you both the generated API and database-level RLS.
@@ -1,99 +0,0 @@
1
- # Mappings
2
-
3
- This page shows how each Quickback primitive maps to RLS policy SQL. The same `firewall` and `access` config used by the [Hono target](/compiler/targets/hono-api) generates these policies — no Supabase-specific re-authoring required.
4
-
5
- ## Schema → Tables
6
-
7
- `defineTable({ schema })` compiles to a Drizzle PostgreSQL schema and a `CREATE TABLE` statement. RLS is enabled on the table by default:
8
-
9
- ```sql
10
- ALTER TABLE projects ENABLE ROW LEVEL SECURITY;
11
- ```
12
-
13
- ## Firewall → `FOR ALL USING`
14
-
15
- Firewall rules isolate data by tenant or owner. They become a single `FOR ALL USING` policy applied to every operation.
16
-
17
- **Org-scoped:**
18
-
19
- ```typescript
20
- firewall: [
21
- { field: 'organizationId', equals: 'ctx.activeOrgId' },
22
- ]
23
- ```
24
-
25
- ```sql
26
- CREATE POLICY "projects_firewall" ON projects FOR ALL
27
- USING (organization_id = public.get_active_org_id());
28
- ```
29
-
30
- **User-scoped:**
31
-
32
- ```typescript
33
- firewall: [
34
- { field: 'userId', equals: 'ctx.userId' },
35
- ]
36
- ```
37
-
38
- ```sql
39
- CREATE POLICY "preferences_firewall" ON preferences FOR ALL
40
- USING (user_id = auth.uid());
41
- ```
42
-
43
- ## Access → `FOR SELECT/INSERT/UPDATE/DELETE USING`
44
-
45
- Access rules layer role-based checks on top of the firewall. Each operation gets its own policy.
46
-
47
- ```typescript
48
- access: {
49
- roles: ['admin', 'member'],
50
- list: { roles: ['admin', 'member'] },
51
- create: { roles: ['admin'] },
52
- update: { roles: ['admin'] },
53
- delete: { roles: ['admin'] },
54
- }
55
- ```
56
-
57
- ```sql
58
- CREATE POLICY "projects_select" ON projects FOR SELECT
59
- USING (
60
- organization_id = public.get_active_org_id()
61
- AND public.has_any_role(ARRAY['admin', 'member'])
62
- );
63
-
64
- CREATE POLICY "projects_insert" ON projects FOR INSERT
65
- WITH CHECK (
66
- organization_id = public.get_active_org_id()
67
- AND public.has_any_role(ARRAY['admin'])
68
- );
69
- ```
70
-
71
- ## Defense in depth — anon deny
72
-
73
- Every generated table gets an explicit deny policy for the `anon` role:
74
-
75
- ```sql
76
- CREATE POLICY "projects_deny_anon" ON projects FOR ALL
77
- TO anon
78
- USING (false);
79
- ```
80
-
81
- Unauthenticated requests are blocked at the database level even if a policy elsewhere is misconfigured.
82
-
83
- ## Helper functions
84
-
85
- Quickback emits a set of helper functions in `0100_create_rls_helpers.sql` that the policies reference:
86
-
87
- | Function | Purpose |
88
- |----------|---------|
89
- | `get_active_org_id()` | Returns the user's active organization from `user_sessions` |
90
- | `has_any_role(roles[])` | Checks if the user has any of the listed roles in the active org |
91
- | `has_org_role(role)` | Checks for a single specific role |
92
- | `is_org_member()` | Checks org membership |
93
- | `get_user_role()` | Returns the user's role in the active org |
94
-
95
- These are used by the generated policies but you can also call them from views, triggers, or stored procedures.
96
-
97
- ## What does not compile
98
-
99
- `defineActions()`, `views`, `masking`, and runtime `guards` do **not** become RLS — see [Limitations](/compiler/targets/supabase-rls/limitations).
@@ -1,88 +0,0 @@
1
- # Setup
2
-
3
- ## Prerequisites
4
-
5
- - A Supabase project (free tier is fine for development)
6
- - The Supabase CLI installed: `npm install -g supabase`
7
- - A Quickback project (`quickback create` or existing)
8
-
9
- ## 1. Configure the target
10
-
11
- ```typescript title="quickback/quickback.config.ts"
12
- import { defineConfig, defineRuntime, defineDatabase, defineAuth } from "@quickback/compiler";
13
-
14
- export default defineConfig({
15
- name: "my-app",
16
- providers: {
17
- runtime: defineRuntime("supabase"),
18
- database: defineDatabase("supabase"),
19
- auth: defineAuth("supabase-auth"),
20
- },
21
- });
22
- ```
23
-
24
- The `supabase-auth` provider tells Quickback to emit RLS policies that reference `auth.uid()` — Supabase's built-in JWT claim function — rather than the Better Auth equivalents used by the Neon target.
25
-
26
- ## 2. Compile
27
-
28
- ```bash
29
- quickback compile
30
- ```
31
-
32
- This generates:
33
-
34
- ```
35
- supabase/
36
- ├── migrations/
37
- │ ├── 0100_create_rls_helpers.sql # get_active_org_id(), has_any_role(), etc.
38
- │ ├── 0101_create_rls_policies.sql # Per-table SELECT/INSERT/UPDATE/DELETE policies
39
- │ └── 0102_create_audit_triggers.sql # Optional audit logging
40
- src/
41
- ├── db/
42
- │ └── schema.ts # Drizzle schema (typed access from your app)
43
- ```
44
-
45
- ## 3. Apply migrations
46
-
47
- ```bash
48
- supabase db push
49
- ```
50
-
51
- Supabase applies the migrations to your remote project. RLS is enabled on every generated table and the deny-anon policy is installed.
52
-
53
- ## 4. Use from your app
54
-
55
- Quickback for Supabase doesn't generate API routes. Your application code (PostgREST, Edge Functions, your own server) talks to Supabase as normal — the RLS policies are enforced beneath it.
56
-
57
- ```typescript
58
- import { createClient } from '@supabase/supabase-js';
59
-
60
- const supabase = createClient(SUPABASE_URL, SUPABASE_ANON_KEY, {
61
- global: { headers: { Authorization: `Bearer ${userJwt}` } },
62
- });
63
-
64
- // RLS policies generated by Quickback enforce row-level access
65
- const { data } = await supabase.from('projects').select('*');
66
- ```
67
-
68
- ## Updating the schema
69
-
70
- Edit your `defineTable()` files, recompile, and push:
71
-
72
- ```bash
73
- quickback compile
74
- supabase db push
75
- ```
76
-
77
- The compiler diffs against the previous compilation and emits a new migration only for what changed.
78
-
79
- ## Comparison with the Neon target
80
-
81
- | | Supabase | Neon |
82
- |---|----------|------|
83
- | Auth function | `auth.uid()` | `auth.user_id()` |
84
- | Auth provider | Supabase Auth | Better Auth + Neon Authorize |
85
- | Users table | `auth.users` | `public.users` |
86
- | API code generated | No | Yes (Hono routes) |
87
-
88
- Both targets emit RLS policies. The difference is who issues the JWTs and where the application logic lives.