diff --git a/app/main.py b/app/main.py index 87ee1dc..e7f0ed3 100644 --- a/app/main.py +++ b/app/main.py @@ -1,5 +1,6 @@ from contextlib import asynccontextmanager from pathlib import Path +from urllib.parse import quote from fastapi import FastAPI, Request from fastapi.middleware.cors import CORSMiddleware @@ -45,7 +46,15 @@ def create_app() -> FastAPI: @app.exception_handler(NotAuthenticated) async def _redirect_to_login(request: Request, exc: NotAuthenticated): - return RedirectResponse(url="/login", status_code=302) + # Preserve the originally requested URL so we can return there after + # login. Only meaningful for GET navigations (the ones users deep-link). + login_url = "/login" + if request.method == "GET" and request.url.path not in ("/", "/login"): + target = request.url.path + if request.url.query: + target += "?" + request.url.query + login_url = f"/login?next={quote(target, safe='')}" + return RedirectResponse(url=login_url, status_code=302) @app.get("/healthz", tags=["health"]) async def healthz(): diff --git a/app/templates/login.html b/app/templates/login.html index ee71fce..1fa24e3 100644 --- a/app/templates/login.html +++ b/app/templates/login.html @@ -9,6 +9,7 @@ {% if ldap_enabled %}