Files
newz-qwen-27b/.env.example
Daniel Samson b186d0f797 feat: add JWT authentication with auth pages and tests (M5)
Backend (FastAPI):
- core/auth.py: PBKDF2-HMAC-SHA256 password hashing (120k iterations,
  random salt), HS256 JWT creation/verification (7-day expiry,
  HN_SECRET_KEY via config) and get_current_user Bearer dependency
- models/user.py: User model (username unique/indexed, password_hash,
  created_at); schemas/auth.py: register/login/token/user schemas
- api/v1/auth.py: POST /api/v1/auth/register (201), /login, /logout
  (204), GET /me; 400 on duplicate username, 401 on bad credentials,
  invalid/expired/unknown tokens
- requirements: PyJWT; env templates + docker-compose expose
  HN_SECRET_KEY (dev default, override in production)
- tests: 24 new backend tests (hashing, tokens, all endpoints)

Frontend (React + TypeScript):
- api/client.ts: AUTH_TOKEN localStorage persistence, automatic
  Bearer token attachment, 401 clears the stored token, typed
  login/register/logout/me helpers
- auth.tsx: AuthProvider (session restore + login/register/logout)
  and RequireAuth route guard
- pages: Login, Register, SignOut and a protected /account
  placeholder; header shows sign-in/register or user/sign-out
- styles: auth component classes in globals.css
- tests: unit tests for the client, provider and pages; Playwright
  E2E spec covering register/login/logout, session restore, invalid
  token cleanup and protected-route redirects (API mocked)

Note: the milestone's /api/auth/* paths map to the project's
established /api/v1/* prefix (see M2); the HN_SECRET_KEY default is
newzy-dev-secret-change-me.
2026-10-30 17:03:00 +00:00

35 lines
1.7 KiB
Bash

# newzy — environment variable template.
#
# Copy to `.env` and adjust as needed:
#
# cp .env.example .env
#
# `docker compose` in this directory reads `.env` automatically. `.env` is
# excluded from version control (see .gitignore) — never commit secrets.
# The backend's own defaults are documented in `backend/.env.example`.
# --- Database -------------------------------------------------------------
# SQLite database location (SQLAlchemy URL, relative to the backend's
# working directory). Inside the Docker image this resolves to
# /app/data/db/newzy.db, which is bind-mounted to ./data/db on the host.
DATABASE_URL=sqlite:///./data/db/newzy.db
# --- Backend ----------------------------------------------------------------
# Enable debug mode (verbose logs; keep off in production).
DEBUG=false
# JWT signing key (HS256) used by the backend auth endpoints. Change this
# before deploying publicly — the dev default is not secret.
HN_SECRET_KEY=newzy-dev-secret-change-me
# Comma-separated list of origins the backend allows for CORS. The Docker
# frontend proxies /api (same-origin, no CORS needed); this mainly matters
# when developing the frontend directly on http://localhost:5173.
BACKEND_CORS_ORIGINS=http://localhost:3000,http://localhost:5173
# --- Frontend ----------------------------------------------------------------
# Base URL the frontend uses to reach the backend API.
# /api -> relative (recommended: the Vite dev server and the
# Docker Nginx config both proxy /api to the backend)
# http://host:port -> absolute (cross-origin; the origin must be listed in
# BACKEND_CORS_ORIGINS)
FRONTEND_API_URL=/api