Auth Flow
The platform uses two separate authentication mechanisms depending on who is making the request.
Admin and Publisher Auth (JWT)
Section titled “Admin and Publisher Auth (JWT)”Editors and publishers authenticate with a username and password. The backend issues a JWT token that the dashboard stores and sends with every request.
Admin/Publisher Login Flow
- User POSTs credentials to /api/v1/auth/login.
- Backend validates credentials and signs a JWT containing the user ID and role.
- Dashboard stores the JWT (localStorage or context) and attaches it to all future requests.
- Each protected request includes: Authorization: Bearer <token>
- protect middleware verifies the token and attaches req.user to the request.
- admin or publisher middleware then checks the role before allowing the action.
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...Middleware Types
Section titled “Middleware Types”| Middleware | What it checks |
|---|---|
protect | Token is valid and user exists — all logged-in users pass |
admin | User role is admin — full access |
publisher | User role is publisher — limited to own feed/articles |
Child-Site Auth (API Key)
Section titled “Child-Site Auth (API Key)”Child-site frontends don’t have user accounts. They authenticate using a shared API key.
Child-Site API Key Flow
- Child-site frontend calls an endpoint under /api/v1/client/*.
- Request includes the API key as a header or query param.
- authenticateApiKey middleware compares it to the API_KEY env var.
- Backend returns the content or responds with 403.
x-api-key: your-api-key-hereOr as a query param:
GET /api/v1/client/posts?api_key=your-api-key-here