From 277f5d58cb66d5d8a501ed233b0c20cbda960578 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8E=E5=B0=8F=E4=B8=98?= Date: Thu, 6 Mar 2025 09:17:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E5=AE=98=E6=96=B9=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E9=87=8D=E5=AE=9A=E5=90=91=E6=96=B9=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 2ad144c..e74685f 100644 --- a/main.py +++ b/main.py @@ -47,14 +47,14 @@ class AuthMiddleware(BaseHTTPMiddleware): logging.info(f"访问路径: {request.url.path}," f"认证状态: {app.storage.user.get('authenticated')}") if not app.storage.user.get('authenticated', False): - # 如果请求的路径在Client.page_routes.values()中,并且不在unrestricted_page_routes中 - if request.url.path in Client.page_routes.values() \ + # 如果请求的路径不是nicegui的静态文件,并且不在unrestricted_page_routes中 + if not request.url.path.startwith('/_nicegui') \ and request.url.path in AUTH_CONFIG["restricted_routes"]: logging.warning(f"未认证用户尝试访问: {request.url.path}") # 记录用户想访问的路径 Record the user's intended path app.storage.user['referrer_path'] = request.url.path # 重定向到登录页面 Redirect to the login page - return RedirectResponse(AUTH_CONFIG["login_url"]) + return RedirectResponse(f'/login?redirect_to={request.url.path}') # 否则,继续处理请求 Otherwise, continue processing the request return await call_next(request)