🔀 Reading: Pull Requests & Code Reviews
3 exercises — read authentic PR descriptions and code review comments. Extract key information, understand dependencies, and classify reviewer feedback.
What to look for in a PR description
- What changed — the list of modifications
- Why — the motivation or linked issue
- How to test — the step-by-step test plan
- Dependencies — other PRs or issues to be aware of
0 / 3 completed
1 / 3
Pull Request Description
## Summary
Adds JWT-based authentication to the REST API. Previously all endpoints were publicly accessible.
## Changes
- Added `AuthMiddleware` class that validates Bearer tokens on protected routes
- Integrated with existing `UserService` to look up users by token claims
- Updated `/api/users` and `/api/orders` routes to require authentication
- Added `/api/auth/login` endpoint (POST) — returns a signed JWT on valid credentials
- Public endpoints (`/api/health`, `/api/docs`) remain unauthenticated
## How to Test
1. Start the server: `npm run dev`
2. Try accessing `GET /api/users` without a token → expect `401 Unauthorized`
3. POST to `/api/auth/login` with valid credentials → extract the JWT from response
4. Retry `GET /api/users` with `Authorization: Bearer <token>` header → expect `200 OK`
5. Test with expired token (set `JWT_EXPIRES_IN=1s` in .env and wait) → expect `401`
## Related Issues
Closes #312 — Security: unprotected API endpoints
Depends on #298 — UserService refactor (already merged) According to the PR description, which of the following endpoints does NOT require authentication after this change?
/api/health — explicitly listed as a public endpoint:
The PR description contains this line: "Public endpoints (/api/health, /api/docs) remain unauthenticated."
This tells you the author explicitly thought about which routes should remain public:
A well-structured PR description should always answer:
① What changed? — the Changes section
② Why? — the Summary (context, motivation)
③ How to test? — step-by-step test plan
④ What are the dependencies? — related issues/PRs
Reading strategy: Scan for bullet points and specific technical details. The granular list of changed routes is exactly what reviewers need to safely approve this PR.
The PR description contains this line: "Public endpoints (/api/health, /api/docs) remain unauthenticated."
This tells you the author explicitly thought about which routes should remain public:
/api/health→ public (health checks are often used by load balancers and monitoring systems — they can't authenticate)/api/docs→ public (API documentation is typically readable without auth)/api/users→ now protected ✅/api/orders→ now protected ✅
A well-structured PR description should always answer:
① What changed? — the Changes section
② Why? — the Summary (context, motivation)
③ How to test? — step-by-step test plan
④ What are the dependencies? — related issues/PRs
Reading strategy: Scan for bullet points and specific technical details. The granular list of changed routes is exactly what reviewers need to safely approve this PR.