Skip to content

Commit

Permalink
Fix: Fix infinite request loop
Browse files Browse the repository at this point in the history
  • Loading branch information
sevenc-nanashi committed Aug 29, 2024
1 parent f64166f commit 5baedb7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 3 additions & 3 deletions frontend/app/routes/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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")}`;

Expand Down Expand Up @@ -57,9 +57,9 @@ const Login = () => {
<h1 className="page-title">{t("title")}</h1>
<p>
<Trans
i18nKey="header:login.description"
i18nKey="menu:login.description"
components={[
<Link key={0} to={loginState?.url || ""} target="_blank" />,
<a key={0} href={loginState?.url.toString()} target="_blank" />,
]}
/>
</p>
Expand Down
7 changes: 6 additions & 1 deletion frontend/lib/requireLogin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ const requireLogin = <T extends React.FC<never>>(component: T) => {
return (props: never) => {
const session = useSession();
const navigate = useNavigate();

useEffect(() => {
if (session?.loggedIn === false) {
navigate("/login");
}
}, [session]);
if (!session) return <div />;
if (session.loggedIn) return createElement(component, props);
navigate("/login");
return <div />;
};
};
Expand Down

0 comments on commit 5baedb7

Please sign in to comment.