Remove AuthMiddleware, add direct session check in root endpoint only
Browse files24 unmodified lines2526272829303132333435363721 unmodified lines5960616263646566676824 unmodified linesallow_headers=["*"],)# Setup authentication middleware and session management# Must be done BEFORE importing routers so middleware order is correctfrom app.auth import setup_auth, AuthMiddlewarefrom app.config import settingssetup_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 linesfrom app.auth import get_login_htmlreturn HTMLResponse(content=get_login_html())# Root endpoint - serves dashboard@app.get("/", response_class=HTMLResponse)async def root():"""Serve the main dashboard"""template_path = os.path.join(os.path.dirname(__file__), "templates", "dashboard.html")try:with open(template_path, 'r') as f:24 unmodified lines252627282930313233343521 unmodified lines57585960616263646566676869707172737475767724 unmodified linesallow_headers=["*"],)# Setup authentication - session middleware only (no custom middleware)from app.auth import setup_authfrom app.config import settingssetup_auth(app) # Adds session middleware# Import routers AFTER app is created and middleware is configuredfrom app.routers import models, datasets, training, system, jobs21 unmodified linesfrom app.auth import get_login_htmlreturn HTMLResponse(content=get_login_html())# Root endpoint - serves dashboard (with auth check)@app.get("/", response_class=HTMLResponse)async def root(request: Request):"""Serve the main dashboard - check auth first if enabled"""# Check if auth is required and user is logged inif settings.APP_PASSWORD:from app.auth import is_authenticatedif not is_authenticated(request):# Redirect to login pagereturn 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