Skip to content
v2.7

Database permissions

Table permissions, row security and how the two add up.

The database uses permissions and roles at two levels. They apply to callers using the user’s session (the web app); the server, with an API key, accesses data according to the key’s scopes.

They live in the Table settings (console) or in the permissions of createTable/updateTable. They apply to all rows.

Example Effect
Permission.read(Role.any()) public catalog: anyone can read
Permission.create(Role.users()) any signed-in user creates rows
Permission.read(Role.team('team')), Permission.write(Role.team('team')) only the team reads and writes

With row security on (rowSecurity: true), each row can have its own permissions, added to the table’s. Whoever has read access on the table reads all rows; whoever doesn’t reads only the rows that grant them read access.

A common pattern, “each user sees only their own data”:

  1. A table with Permission.create(Role.users()) and row security on.
  2. Each row the user creates gets read, update and delete for Role.user(<their id>). This is what happens when createRow comes from the browser without permissions.

The summary is in Permissions. The full list:

Permission. Applies to
read(role) read
create(role) create (on tables and buckets)
update(role) update
delete(role) delete
write(role) shortcut for create, update and delete
Role. Who
any() anyone, signed in or not
guests() only those who are not signed in
users() any signed-in user (users('verified'): only with a confirmed email)
user(id) a specific user
team(id) members of the team (team(id, 'editor'): only with the editor role in the team)
member(id) a specific membership in a team
label(name) users with that label (labels are set by the server)
permissoes.ts (browser)
import { ID, Permission, Role, TablesDB } from '@owbase/web';
import { client } from './client';
const db = new TablesDB(client);
const author = '<USER_ID>';
// From the browser, the user can only grant roles they hold themselves: their own ID, their teams, "users" and "any".
// Here, anyone reads; only the author edits and deletes.
await db.createRow({
databaseId: 'store',
tableId: 'reviews',
rowId: ID.unique(),
data: { rating: 5, text: 'Arrived fast.' },
permissions: [Permission.read(Role.any()), Permission.update(Role.user(author)), Permission.delete(Role.user(author))],
});

In the browser (without an API key), the user can only grant roles they hold themselves: their own ID, the teams they belong to, users() and any(). Asking for Role.user(<someone else>) or another team is rejected. Granting access to other people and teams is the server’s job, with an API key:

permissoes.ts (server)
import { ID, Permission, Role, TablesDB } from '@owbase/node';
import { client } from './client';
// The key needs the rows.write scope. With an API key, you can grant access to any user or team.
const db = new TablesDB(client);
const author = '<USER_ID>';
// Only the author reads, edits and deletes; members of the "moderation" team can also read.
await db.createRow({
databaseId: 'store',
tableId: 'reviews',
rowId: ID.unique(),
data: { rating: 5, text: 'Arrived fast.' },
permissions: [
Permission.read(Role.user(author)),
Permission.update(Role.user(author)),
Permission.delete(Role.user(author)),
Permission.read(Role.team('moderation')),
],
});

When the user creates a row without providing permissions, they get read, update and delete on it. To give access to other people, provide the full list.

Was this page helpful?