Express + Postgres + OpenFGA reference implementing blog roles and per-post permissions.
- Users with roles: admin, editor, moderator, viewer (via OpenFGA tuples)
- Posts: draft by default; publish flow; ownership transfer; per-post edit grants
- Email-only login issuing JWT
- Docker Compose with Postgres and OpenFGA (plus Playground)
- Swagger docs at /docs
- Copy env:
cp .env.example .envand adjust if needed. - Start:
docker compose up --build. - Open API: http://localhost:3000/docs
- OpenFGA Playground: http://localhost:3001
- Create an admin: call
POST /auth/loginwith your email. Copyuser.id. - Grant yourself admin role: use OpenFGA Playground to add tuple
user:<YOUR_ID> admin user:<YOUR_ID>or callPOST /users/{id}/rolesfrom another admin. - Create other users via
/auth/loginthen assign roles with/users/{userId}/roles.
See src/openfga/model.json. Key relations on post:
- owner: the post owner
- granted_editor: per-post granted editor (admin-granted), used by moderators
- can_edit: owner OR admin OR moderator with per-post grant
- can_delete: owner OR admin OR moderator with per-post grant (and own)
- can_publish: admin OR moderator
Swagger at src/swagger.yaml documents request/response and auth.
- This example keeps user roles as OpenFGA tuples under
usertype. - Data migrations are under
sql/init.sql.