From acbb87881187f71775e7d735c524ecd2d233a9a0 Mon Sep 17 00:00:00 2001 From: AINDUSTRIES Date: Wed, 22 Jul 2026 20:49:33 -0400 Subject: [PATCH] Added a login guard --- app/components/guard.tsx | 62 ++++++++++++++++++++++++++++++++++++++++ app/pages/base.tsx | 10 +++++-- app/pages/gamemodes.tsx | 6 ++-- app/pages/inventory.tsx | 6 ++-- app/pages/maps.tsx | 2 +- 5 files changed, 76 insertions(+), 10 deletions(-) create mode 100644 app/components/guard.tsx diff --git a/app/components/guard.tsx b/app/components/guard.tsx new file mode 100644 index 0000000..c85b6dd --- /dev/null +++ b/app/components/guard.tsx @@ -0,0 +1,62 @@ +import type { PropsWithChildren } from "react"; +import { useNavigate } from "react-router"; +import { useAuth } from "~/hooks/auth"; +import { Button, Modal, Spinner } from "@heroui/react"; + +export default function Guard({ children }: PropsWithChildren) { + const { user, loading, login, logout } = useAuth(); + const navigate = useNavigate(); + + if (loading) { + return ( +
+ +
+ ); + } + + if (user !== null) { + return children; + } + + return ( + <> +
+ + + + + + + Login required. + + + +

+ To view this page, you need to be logged + in with your Steam account. +

+
+ + + + +
+
+
+
+
+ + ); +} diff --git a/app/pages/base.tsx b/app/pages/base.tsx index 5519ed5..7ed3fe4 100644 --- a/app/pages/base.tsx +++ b/app/pages/base.tsx @@ -1,13 +1,17 @@ import type { PropsWithChildren } from "react"; import { Footer } from "~/components/footer"; +import Guard from "~/components/guard"; import { Header } from "~/components/header"; -export default function Base({ children }: PropsWithChildren) { +export default function Base({ + children, + needsLogin = false, +}: PropsWithChildren<{ needsLogin?: boolean }>) { return ( <>
-
- {children} +
+ {needsLogin ? {children} : children}
diff --git a/app/pages/gamemodes.tsx b/app/pages/gamemodes.tsx index c39d7fa..b88193c 100644 --- a/app/pages/gamemodes.tsx +++ b/app/pages/gamemodes.tsx @@ -1,5 +1,5 @@ -import Base from "./base" +import Base from "./base"; export function GamemodesPage() { - return GAMEMODES -} \ No newline at end of file + return GAMEMODES; +} diff --git a/app/pages/inventory.tsx b/app/pages/inventory.tsx index 2c7d63a..9f88ae1 100644 --- a/app/pages/inventory.tsx +++ b/app/pages/inventory.tsx @@ -1,5 +1,5 @@ -import Base from "./base" +import Base from "./base"; export function InventoryPage() { - return INVENTORY -} \ No newline at end of file + return INVENTORY; +} diff --git a/app/pages/maps.tsx b/app/pages/maps.tsx index f34bf2c..b0879a8 100644 --- a/app/pages/maps.tsx +++ b/app/pages/maps.tsx @@ -1,5 +1,5 @@ import Base from "./base" export function MapsPage() { - return MAPS + return MAPS } \ No newline at end of file