From cc8b436db487898decec54b30f7c8c3f87baa8e9 Mon Sep 17 00:00:00 2001 From: Sven Augustin Date: Tue, 12 May 2026 11:30:58 +0200 Subject: [PATCH] simpler focus; the default None is falsey anyway --- auth/login.py | 11 +++-------- auth/mw.py | 2 +- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/auth/login.py b/auth/login.py index b8d21a4..a5995a8 100644 --- a/auth/login.py +++ b/auth/login.py @@ -12,17 +12,17 @@ router = APIRouter() @router.page("/login") def login(redirect_to: str = "/") -> RedirectResponse | None: - if app.storage.user.get("authenticated", False): + if app.storage.user.get("authenticated"): return RedirectResponse("/") def try_login(): # local function to avoid passing username and password as arguments if not username.value: ui.notify("Missing username", color="negative") - focus(username) + username.run_method("focus") return if not password.value: - focus(password) + password.run_method("focus") return if passwords.get(username.value) != password.value: @@ -49,8 +49,3 @@ def login(redirect_to: str = "/") -> RedirectResponse | None: -def focus(element): - ui.run_javascript(f"getElement({element.id}).$refs.qRef.focus()") - - - diff --git a/auth/mw.py b/auth/mw.py index 57cd77f..5100e18 100644 --- a/auth/mw.py +++ b/auth/mw.py @@ -17,7 +17,7 @@ class AuthMiddleware(BaseHTTPMiddleware): path = request.url.path if ( - app.storage.user.get("authenticated", False) + app.storage.user.get("authenticated") or path in unrestricted_page_routes or path.startswith("/_nicegui") ):