feat: protect write endpoints with JWT auth (story #08) #9

Merged
julia merged 1 commits from feature/08-authorize-user into main 2026-06-19 10:10:20 +00:00
Owner

Summary

  • Add backend/internal/auth package: bcrypt verify (username:password pepper), JWT generate/validate (HS256, 1h expiry)
  • JWT middleware applied to all POST/PUT/DELETE routes; admin group gets group-level middleware
  • POST /api/v1/auth/login endpoint reads user map from USERS_FILE env
  • Pinia authStore persists JWT in localStorage; bearerHeader() / handleUnauthorized() shared by all API modules
  • LoginView with redirect-after-login support; router guard on /fruits/new, /publications/new, /admin
  • v-if="auth.isLoggedIn" guards on all CRUD buttons and admin nav link
  • scripts/create_user.sh generates bcrypt hash entries for users.env

Test plan

  • make test passes (Go auth/middleware/handler tests + Vitest authStore tests)
  • Unauthenticated user: CRUD buttons hidden, write API returns 401
  • Login with valid credentials → redirected to original destination
  • Invalid credentials → error message shown
  • JWT expiry → auto-logout on next write attempt
  • Admin nav link visible only when logged in

🤖 Generated with Claude Code

## Summary - Add `backend/internal/auth` package: bcrypt verify (username:password pepper), JWT generate/validate (HS256, 1h expiry) - JWT middleware applied to all POST/PUT/DELETE routes; admin group gets group-level middleware - `POST /api/v1/auth/login` endpoint reads user map from `USERS_FILE` env - Pinia `authStore` persists JWT in localStorage; `bearerHeader()` / `handleUnauthorized()` shared by all API modules - `LoginView` with redirect-after-login support; router guard on `/fruits/new`, `/publications/new`, `/admin` - `v-if="auth.isLoggedIn"` guards on all CRUD buttons and admin nav link - `scripts/create_user.sh` generates bcrypt hash entries for `users.env` ## Test plan - [ ] `make test` passes (Go auth/middleware/handler tests + Vitest authStore tests) - [ ] Unauthenticated user: CRUD buttons hidden, write API returns 401 - [ ] Login with valid credentials → redirected to original destination - [ ] Invalid credentials → error message shown - [ ] JWT expiry → auto-logout on next write attempt - [ ] Admin nav link visible only when logged in 🤖 Generated with [Claude Code](https://claude.com/claude-code)
julia added 1 commit 2026-06-19 10:05:46 +00:00
Add bcrypt user file auth, JWT middleware on all write routes, Pinia
authStore with localStorage persistence, login view with redirect
support, and v-if guards on all CRUD controls and admin nav link.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
julia merged commit e14aa0fea6 into main 2026-06-19 10:10:20 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: julia/osdb-1-claude-opusplan#9