From 5baedb7533b5794d00f525b11984727829a1ab65 Mon Sep 17 00:00:00 2001 From: sevenc-nanashi Date: Thu, 29 Aug 2024 20:48:56 +0900 Subject: [PATCH] Fix: Fix infinite request loop --- frontend/app/routes/login.tsx | 6 +++--- frontend/lib/requireLogin.tsx | 7 ++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/frontend/app/routes/login.tsx b/frontend/app/routes/login.tsx index cbbf8ef..0c6e2fd 100644 --- a/frontend/app/routes/login.tsx +++ b/frontend/app/routes/login.tsx @@ -12,7 +12,7 @@ import { useLogin } from "~/lib/useLogin.ts"; export const loader = async ({ request }: LoaderFunctionArgs) => { const locale = await detectLocale(request); const rootT = await i18n.getFixedT(locale, "root"); - const t = await i18n.getFixedT(locale, "liked"); + const t = await i18n.getFixedT(locale, "login"); const title = `${t("title")} | ${rootT("name")}`; @@ -57,9 +57,9 @@ const Login = () => {

{t("title")}

, + , ]} />

diff --git a/frontend/lib/requireLogin.tsx b/frontend/lib/requireLogin.tsx index 24c9aba..e7205c5 100644 --- a/frontend/lib/requireLogin.tsx +++ b/frontend/lib/requireLogin.tsx @@ -6,9 +6,14 @@ const requireLogin = >(component: T) => { return (props: never) => { const session = useSession(); const navigate = useNavigate(); + + useEffect(() => { + if (session?.loggedIn === false) { + navigate("/login"); + } + }, [session]); if (!session) return
; if (session.loggedIn) return createElement(component, props); - navigate("/login"); return
; }; };