salary-benchmark/app/deps.py
DJP e9b9c66423 Add login (JWT + local admin user) and deploy script for optical-dev
- Backend: users table + admin seed (004), /api/auth endpoints, JWT auth
  dep gating benchmarks + research routes
- Frontend: AuthContext, LoginPage, ProtectedRoute, subpath-aware via
  VITE_BASE / import.meta.env.BASE_URL so same build works at /opt/
- deploy/: Dockerfile.prod, docker-compose.prod.yml, Apache vhost
  fragment template, and idempotent deploy.sh (port scan, rsync, env
  generation, Apache Include + reload)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-17 19:34:15 -04:00

22 lines
942 B
Python

from fastapi import Depends, Header, HTTPException, status
from sqlalchemy.ext.asyncio import AsyncSession
from app.database import get_db
from app.models import User
from app.services.auth_service import decode_token, get_user_by_id
async def get_current_user(
authorization: str | None = Header(default=None),
db: AsyncSession = Depends(get_db),
) -> User:
if not authorization or not authorization.lower().startswith("bearer "):
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Not authenticated")
token = authorization.split(" ", 1)[1].strip()
user_id = decode_token(token)
if user_id is None:
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid token")
user = await get_user_by_id(db, user_id)
if not user or not user.is_active:
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Inactive user")
return user