Implemented full FastAPI backend with WebSocket support, database models, and comprehensive documentation for the Paper Dynasty game engine. Backend Implementation: - FastAPI application with Socket.io WebSocket server - SQLAlchemy async database models (Game, Play, Lineup, GameSession) - PostgreSQL connection to dev server (10.10.0.42:5432) - Connection manager for WebSocket lifecycle - JWT authentication utilities - Health check and stub API endpoints - Rotating file logger with Pendulum datetime handling - Redis via Docker Compose for caching Technical Details: - Python 3.13 with updated package versions - Pendulum 3.0 for all datetime operations - Greenlet for SQLAlchemy async support - Fixed SQLAlchemy reserved column names (metadata -> *_metadata) - Pydantic Settings with JSON array format for lists - Docker Compose V2 commands Documentation: - Updated backend/CLAUDE.md with environment-specific details - Created .claude/ENVIRONMENT.md for gotchas and quirks - Created QUICKSTART.md for developer onboarding - Documented all critical learnings and troubleshooting steps Database: - Tables created: games, plays, lineups, game_sessions - All indexes and foreign keys configured - Successfully tested connection and health checks Verified: - Server starts at http://localhost:8000 - Health endpoints responding - Database connection working - WebSocket infrastructure functional - Hot-reload working 🎯 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
57 lines
1.4 KiB
Python
57 lines
1.4 KiB
Python
import logging
|
|
from fastapi import APIRouter, HTTPException
|
|
from pydantic import BaseModel
|
|
|
|
from app.utils.auth import create_token
|
|
|
|
logger = logging.getLogger(f'{__name__}.auth')
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
class TokenRequest(BaseModel):
|
|
"""Request model for token creation"""
|
|
user_id: str
|
|
username: str
|
|
discord_id: str
|
|
|
|
|
|
class TokenResponse(BaseModel):
|
|
"""Response model for token creation"""
|
|
access_token: str
|
|
token_type: str = "bearer"
|
|
|
|
|
|
@router.post("/token", response_model=TokenResponse)
|
|
async def create_auth_token(request: TokenRequest):
|
|
"""
|
|
Create JWT token for authenticated user
|
|
|
|
TODO Phase 1: Implement Discord OAuth flow
|
|
For now, this is a stub that creates tokens from provided user data
|
|
"""
|
|
try:
|
|
user_data = {
|
|
"user_id": request.user_id,
|
|
"username": request.username,
|
|
"discord_id": request.discord_id
|
|
}
|
|
|
|
token = create_token(user_data)
|
|
|
|
return TokenResponse(access_token=token)
|
|
|
|
except Exception as e:
|
|
logger.error(f"Token creation error: {e}")
|
|
raise HTTPException(status_code=500, detail="Failed to create token")
|
|
|
|
|
|
@router.get("/verify")
|
|
async def verify_auth():
|
|
"""
|
|
Verify authentication status
|
|
|
|
TODO Phase 1: Implement full auth verification
|
|
"""
|
|
return {"authenticated": True, "message": "Auth verification stub"}
|