One table, many customers, each seeing their own.

Give customers, students or partners an app of their own. They sign in to a pool kept apart from your staff, and the database itself makes sure each person gets only their rows.

Who sees which rows.

Acme's customers each see their own company's invoices, and finance sees them all, in one table, through one app. The rule sits on the table, so it holds for the app, for any script acting for the customer, and for any query.

  • A customer's customer_id is an attribute on their account, set by staff on their record.
  • A row matches when its column equals that attribute. No match, no row, whatever the app asks for.
  • Someone not signed in reaches only what's bound to "anyone", such as Acme's public notices.

Two rules, one table.

The finance group reads and changes every invoice. Each customer reads their own company's. That's the whole of it.

  • Groups come from the tenant's sign-in, or from its identity provider.
  • The same rule shapes work for an owner column, a group or an attribute.
  • Preview the rows as one end user would before anyone signs in.
examples/acme/src/index.tsdefineTable
export const invoices = defineTable({
  path: "invoices",
  columns: {
    number: column.text({ required: true, unique: true }),
    total: column.number({ required: true }),
    customer_id: column.text({ required: true }),
    visible_to: column.text({ default: "finance" }),
  },
  policy: {
    rules: [
      { allow: "all", when: { column: "visible_to", in: "groups" } },
      { allow: "read",
        when: { column: "customer_id", equals: { attribute: "customer_id" } } },
    ],
  },
});

From examples/acme.

Three portals from the examples.

Different people, different screens, the same few ideas underneath.

PortalWho signs inWhat decides their rows
Fernhill pet portalPet owners, in React: their pets, visits, booking and invoicesA client_id on each owner, matched against every table that names a client
Borrow a deviceLakeshore's students, with no code: ask for a device, see requests and loansA student_id on each student. Every device is visible, their own records only
Acme ordersAcme's customers, in React: their orders, and a form to ask for oneEach order's owner. A request is written as the person who made it, so it's theirs from the start

The people outside the company.

End users are their own pool, kept apart from your staff, with only the kinds of permission apps use.

A pool per tenant
The same email in two tenants is two people. A customer of one business never shows up in another's.
Invitations that work once
Staff add a person and get a link to pass on, or the instance mails it. Sign-up stays off until the tenant turns it on.
Their own sign-in, if they have one
OIDC or SAML for end users, such as a college's student accounts, with groups that follow the provider.
Hard to over-share
Whatever an end user is bound to, they hold only app-facing permissions. A binding made too wide can't hand them settings or secrets.
On your domain
One hostname the tenant proves it owns serves its sign-in pages and every app under it.
Forms for anyone
A public form, such as Fernhill's new-client registration, served under the portal and limited per visitor.

Open your data to customers, safely.

End users, row rules and your own domain, in open-source Volvel.