From 37ae7c81c029ad0867bc08750d44ed6426c84a2b Mon Sep 17 00:00:00 2001 From: Rodja Trappe Date: Sun, 17 Sep 2023 05:58:40 +0200 Subject: [PATCH] auth demo: using storage instead of query parameter --- examples/authentication/main.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/authentication/main.py b/examples/authentication/main.py index eb9e6078a..d847c7fa5 100755 --- a/examples/authentication/main.py +++ b/examples/authentication/main.py @@ -28,7 +28,8 @@ class AuthMiddleware(BaseHTTPMiddleware): async def dispatch(self, request: Request, call_next): if not app.storage.user.get('authenticated', False): if request.url.path in nicegui.globals.page_routes.values() and request.url.path not in unrestricted_page_routes: - return RedirectResponse(f'/login?referrer_path={quote(request.url.path)}') + app.storage.user['referrer_path'] = request.url.path # remember where the user wanted to go + return RedirectResponse('/login') return await call_next(request) @@ -48,11 +49,11 @@ def test_page() -> None: @ui.page('/login') -def login(referrer_path: str = '') -> Optional[RedirectResponse]: +def login() -> Optional[RedirectResponse]: def try_login() -> None: # local function to avoid passing username and password as arguments if passwords.get(username.value) == password.value: app.storage.user.update({'username': username.value, 'authenticated': True}) - ui.open(referrer_path or '/') + ui.open(app.storage.user.get('referrer_path', '/')) # go back to where the user wanted to go else: ui.notify('Wrong username or password', color='negative')