User-Owned Data & Row-Level Security
Automatic data isolation and row-level privacy for multi-tenant portals, user dashboards, and private application stores.
How User-Ownership Works
Any collection containing a field named user_id (type relation or number) is automatically designated as user-owned. Pottr enforces strict row-level security without requiring custom permissions code:
Read Scoping:
GET /collections/{slug}queries automatically filter to only return entries owned by the authenticated app user (identified by their JWT). Requests without a valid user token receive401 unauthorized.Server-Side ID Injection: When an authenticated user creates an entry (
POST /collections/{slug}), Pottr extracts the user’s ID from their verified JWT and attaches it server-side. Clients should omituser_idfrom the request body.Modification & Deletion Protection: When updating (
PUT/PATCH) or deleting (DELETE), Pottr verifies that the target entry’suser_idmatches the authenticated user. Attempts to read or alter another user’s single entry return403 forbidden.Administrative Access: Requests authenticated with the Secret Key (
sk_live_...) or an active WordPress Administrator session bypass ownership checks, allowing backends and administrators to manage entries across all users.
Example: Creating a User-Owned Entry
// Notice: 'user_id' is NOT included in the body — it is injected server-side from the JWT
const res = await fetch('https://example.com/wp-json/pottr/v1/collections/notes', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.NEXT_PUBLIC_POTTR_PUBLIC_KEY}`,
'X-Pottr-User-Token': userAccessToken,
'Content-Type': 'application/json'
},
body: JSON.stringify({
title: 'My Private Financial Goal',
content: 'Confidential user data'
})
});