Remove AuthMiddleware, add direct session check in root endpoint only
Browse files24 unmodified lines25262728293028293031323433343521 unmodified lines57585962606164656263646566676869707172737475767724 unmodified lines allow_headers=["*"],)
# Setup authentication middleware and session management# Must be done BEFORE importing routers so middleware order is correctfrom app.auth import setup_auth, AuthMiddleware# Setup authentication - session middleware only (no custom middleware)from app.auth import setup_authfrom app.config import settings
setup_auth(app) # Adds session middlewareapp.add_middleware(AuthMiddleware) # Protects routes based on auth config
# Import routers AFTER app is created and middleware is configuredfrom app.routers import models, datasets, training, system, jobs21 unmodified lines from app.auth import get_login_html return HTMLResponse(content=get_login_html())
# Root endpoint - serves dashboard# Root endpoint - serves dashboard (with auth check)@app.get("/", response_class=HTMLResponse)async def root(): """Serve the main dashboard"""async def root(request: Request): """Serve the main dashboard - check auth first if enabled""" # Check if auth is required and user is logged in if settings.APP_PASSWORD: from app.auth import is_authenticated if not is_authenticated(request): # Redirect to login page return HTMLResponse( content='<script>window.location.href="/login";</script>', status_code=302, headers={"location": "/login"} ) template_path = os.path.join(os.path.dirname(__file__), "templates", "dashboard.html") try: with open(template_path, 'r') as f:app/main.py+16-7