From 8089206df1457854b801479ce284bd51bb7c7c6c Mon Sep 17 00:00:00 2001 From: abdou6666 Date: Fri, 7 Feb 2025 17:24:02 +0100 Subject: [PATCH] fix: bug when we have dynamic route default redirection to '/' --- frontend/src/hooks/useAuth.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/frontend/src/hooks/useAuth.ts b/frontend/src/hooks/useAuth.ts index 77fd0f3b..4861cd3e 100755 --- a/frontend/src/hooks/useAuth.ts +++ b/frontend/src/hooks/useAuth.ts @@ -6,7 +6,6 @@ * 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file). */ - import { useRouter } from "next/router"; import { useContext } from "react"; @@ -33,12 +32,14 @@ export const useAuth = () => { export const useLogoutRedirection = () => { const router = useRouter(); + const isDynamicPath = router.pathname.includes("["); const hasPublicPath = PUBLIC_PATHS.includes(router.pathname); + const encodedPath = isDynamicPath + ? encodeURIComponent("/settings") + : encodeURIComponent(router.pathname); const logoutRedirection = async (fullReload: boolean = false) => { if (!hasPublicPath) { - const redirectUrl = `/${RouterType.LOGIN}?redirect=${encodeURIComponent( - router.pathname, - )}`; + const redirectUrl = `/${RouterType.LOGIN}?redirect=${encodedPath}`; if (fullReload) { window.location.replace(redirectUrl);