> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bludia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Build a customer portal

> Guide: a customer portal where customers sign up, see only their own tickets and invoices, and can't see other customers' data. Uses a customers guard, owner row policies, a published knowledge base, and an end_users API key.

Customers sign up, open support tickets, see their invoices, and read published help articles. They never see each other's data.

```text theme={null}
customers (guard)  ──<  tickets        (customer creates; sees own)
                   ──<  invoices       (staff creates; customer sees own)
articles                               (everyone sees published)
```

**1. Collections**

* `customers`: `email` (unique, email format), `full_name`, `company`
* `tickets`: `subject` (required), `body` (Long Text), `status` (Select: open, pending, closed), `priority` (Select)
* `invoices`: `number`, `amount` (Number), `due_date` (Date), `paid` (Boolean)
* `articles`: `title`, `content` (Text Editor), `status` (Select: draft, published)

Relations: `customers` → `tickets` (`one_to_many`), `customers` → `invoices` (`one_to_many`).

**2. Guard**

Guard `customers` on the `customers` collection, login field `email`, registration **on**. Optionally turn on [email verification](https://docs.bludia.com/authentication/email-verification.md).

**3. Permissions for the default user role**

| Collection | Permissions |
| :- | :- |
| `customers` | read, update (their own profile) |
| `tickets` | read, create |
| `invoices` | read |
| `articles` | read |

**4. Row policies**

| Collection | Policy | Result |
| :- | :- | :- |
| `customers` | default (owner) | Customers see only their own record |
| `tickets` | default (owner) | Customers see tickets they opened |
| `invoices` | allow `relation` via customers → invoices | Customers see invoices linked to them, even though staff created them |
| `articles` | allow `field_equals` status = published | Everyone sees published articles |

**5. Protect sensitive fields**

Add a `beforeUpdate` hook on `tickets` that rejects changes to `priority` from customers, and one on `customers` that blocks changes to `email` if you don't want customers changing their login.

**6. Notify support**

`afterInsert` hook on `tickets` that emails your support inbox with `ctx.Msg().Send(...)`.

**7. Frontend**

Create an `end_users` key with your portal's origin. Pages: sign-up, login, my tickets, new ticket, my invoices, help center.

## Test isolation

1. Register two customers, A and B.
2. As A, create a ticket. As B, list tickets: A's ticket must not appear.
3. As B, `GET /collections/tickets/{A's ticket id}`: expect `404`.
4. As B, `PUT` the same ID: expect `404`.

> [!TIP]
>
> Run this test whenever you change roles or policies.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.