1.8 KiB
1.8 KiB
Filing Cabinet API
Node.js/Express API for accounts, JWT-authenticated actions, relationships, and posts.
Run
npm install
npm run dev # nodemon app.js
Configure .env (never commit it):
PORT=3000
JWT_SECRET=<random secret, at least 32 characters>
JWT_EXPIRES_IN=86400
UPLOAD_DIR=./uploads
MAX_UPLOAD_SIZE_BYTES=5242880
Database and graph-database variables are also required by the relevant routes. See .env.example.
Authentication
POST /auth/register and POST /auth/login are public. Every other route requires:
Authorization: Bearer <JWT>
Login returns { id, token, expires_at }. The token is HS256-signed and contains user_id, iat, and exp. Never log or expose tokens, passwords, password hashes, or salts.
API
The compact endpoint contract is in API.md. Unknown body/query fields are rejected with 400; clients must send only documented fields.
Security and ownership
- The API is the authoritative validator; client validation is only UX.
- Registration/login validation and password rules are defined in AUTH_INPUT_POLICY.md.
- Post creation always uses
author_idfrom the verified JWT; clients must not sendauthor_id. - Post edit/delete require that the JWT user owns the post.
/postsis visible to any authenticated user;/posts/mefilters by JWTuser_id.- Relationship creation requires
meto equal the JWT user ID. - Uploads accept only JPEG, PNG, GIF, and WebP, one file named
image, up toMAX_UPLOAD_SIZE_BYTES(default 5 MiB). Files receive random names and are stored underUPLOAD_DIR. - Registration rejects disposable email addresses and weak/reused-pattern passwords. Login failures use the generic
Invalid email or passwordresponse. - Do not expose database errors or stack traces to clients.