fix: resolve template errors, orphaned sessions, and auth redirects
- Fix exercise_id undefined error in log_form.html by using scalar exercise_id instead of exercise.id object reference - Clean up orphaned WorkoutSession records when all logs are deleted - Filter empty sessions from dashboard stats (sessions, volume, streak) - Replace broken HTTPException auth redirect with custom exception handler that properly returns 302 to /login Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -17,6 +17,7 @@ from sqlmodel import SQLModel, Session
|
||||
from starlette.middleware.base import BaseHTTPMiddleware, RequestResponseEndpoint
|
||||
from starlette.requests import Request as StarletteRequest
|
||||
from starlette.responses import Response
|
||||
from fastapi.responses import RedirectResponse
|
||||
|
||||
from app.models.user import User
|
||||
from app.config import get_settings
|
||||
@@ -35,7 +36,7 @@ from app.routes.schedule import router as schedule_router
|
||||
from app.services.seed_service import SeedService
|
||||
from app.services.auth_service import AuthService
|
||||
from app.services.user_service import UserService
|
||||
from app.utils.auth import SESSION_COOKIE_NAME
|
||||
from app.utils.auth import SESSION_COOKIE_NAME, NotAuthenticatedError
|
||||
|
||||
logger = structlog.get_logger(__name__)
|
||||
|
||||
@@ -91,6 +92,11 @@ def create_app() -> FastAPI:
|
||||
version="0.1.0",
|
||||
)
|
||||
|
||||
# Redirect unauthenticated requests to login
|
||||
@app.exception_handler(NotAuthenticatedError)
|
||||
async def _not_authenticated_handler(request, exc):
|
||||
return RedirectResponse(url="/login", status_code=302)
|
||||
|
||||
# Mount static files
|
||||
app.mount("/static", StaticFiles(directory=str(STATIC_DIR)), name="static")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user