From e5641b806853da29b649082fa0a5d3a0eb87b659 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Thu, 1 Feb 2024 21:42:47 +0800 Subject: [PATCH] :bug: Fix guard generate redirect uri ignore query strings --- pkg/view/src/layouts/RootLayout.tsx | 7 ++++--- pkg/view/src/pages/auth/login.tsx | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/view/src/layouts/RootLayout.tsx b/pkg/view/src/layouts/RootLayout.tsx index 475c644..0d8ab15 100644 --- a/pkg/view/src/layouts/RootLayout.tsx +++ b/pkg/view/src/layouts/RootLayout.tsx @@ -21,15 +21,16 @@ export default function RootLayout(props: any) { }, [ready, userinfo]); function keepGate(path: string, e?: BeforeLeaveEventArgs) { + const pathname = path.split("?")[0]; const whitelist = ["/auth/login", "/auth/register", "/users/me/confirm"]; - if (!userinfo?.isLoggedIn && !whitelist.includes(path)) { + if (!userinfo?.isLoggedIn && !whitelist.includes(pathname)) { if (!e?.defaultPrevented) e?.preventDefault(); - navigate(`/auth/login?redirect_uri=${path}`); + navigate(`/auth/login?redirect_uri=${encodeURIComponent(path)}`); } } - useBeforeLeave((e: BeforeLeaveEventArgs) => keepGate(e.to.toString().split("?")[0], e)); + useBeforeLeave((e: BeforeLeaveEventArgs) => keepGate(e.to.toString(), e)); return (