diff --git a/src/app/(unauth)/layout.tsx b/src/app/(unauth)/layout.tsx index bd2db05..0ed8380 100644 --- a/src/app/(unauth)/layout.tsx +++ b/src/app/(unauth)/layout.tsx @@ -1,4 +1,3 @@ - import { Inter } from "next/font/google"; import "../globals.scss"; @@ -6,18 +5,9 @@ import ThemeContext from "../ThemeProvider"; const inter = Inter({ subsets: ["latin"] }); export default function RootLayout({ - children, - }: Readonly<{ - children: React.ReactNode; - }>) { - return ( - - - - {children} - - - - ); - } - \ No newline at end of file + children, +}: Readonly<{ + children: React.ReactNode; +}>) { + return <>{children}; +} diff --git a/src/app/ThemeProvider.tsx b/src/app/ThemeProvider.tsx index a1b0454..9a2405a 100644 --- a/src/app/ThemeProvider.tsx +++ b/src/app/ThemeProvider.tsx @@ -3,9 +3,9 @@ import { ThemeProvider } from "@/components/theme-provider"; import { getQueryClient } from "@/lib/get-query-client"; import { - defaultShouldDehydrateQuery, - isServer, - QueryClient, + // defaultShouldDehydrateQuery, + // isServer, + // QueryClient, QueryClientProvider, } from "@tanstack/react-query"; import { PropsWithChildren } from "react"; diff --git a/src/components/custom/LayoutPanel.tsx b/src/components/custom/LayoutPanel.tsx index 27df645..4b8a1c3 100644 --- a/src/components/custom/LayoutPanel.tsx +++ b/src/components/custom/LayoutPanel.tsx @@ -1,6 +1,6 @@ "use client"; -import { PropsWithChildren } from "react"; +import { PropsWithChildren, useEffect } from "react"; import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels"; import Sidebar from "./Sidebar"; import ResizeHandle from "./ResizeHandle"; @@ -9,49 +9,64 @@ import ThemeSwitch from "@/components/atoms/ThemeSwitch"; import { Layout, LayoutHeader, LayoutBody } from "@/components/custom/Layout"; import { UserNav } from "@/components/molecules/UserNav"; import DynamicTopNav from "../molecules/DynamicTopNav"; +import { useSuspenseQuery } from "@tanstack/react-query"; +import { validateAuth } from "@/lib/api"; +import { useRouter } from "next/navigation"; export default function LayoutPanel({ children }: PropsWithChildren) { const { attachHandle, onResize } = useSetLayout(); const { minSize, maxSize } = useGetLayout(); + const { data: isLoggedIn, isLoading } = useSuspenseQuery(validateAuth); + const router = useRouter(); + + // const checkAuth = async () => {}; + + useEffect(() => { + if (!isLoading && !isLoggedIn) { + console.log("[auth]", { isLoggedIn }); + // redirect to auth page + router.push('/login') + } + }, [isLoggedIn, isLoading, router]); return (
- - - - - - - - - - - -
- {/* */} - - -
-
- {children} -
-
-
+ + + + + + + + + + +
+ {/* */} + + +
+
+ {children} +
+
+
); } diff --git a/src/components/molecules/Dashboard.tsx b/src/components/molecules/Dashboard.tsx index 3a6f8eb..99e440b 100644 --- a/src/components/molecules/Dashboard.tsx +++ b/src/components/molecules/Dashboard.tsx @@ -39,7 +39,6 @@ function IncomingFeature() { } export default function Dashboard() { - const downloadReport = async () => { const response = await fetch("/api/download", { credentials: "include" }); const blob = await response.blob(); @@ -56,27 +55,23 @@ export default function Dashboard() { return ( <>
-

-
- -
+ {/*

*/}
-
- - Overview - Analytics - Reports - Notifications - +
+
+ + Overview + Analytics + Reports + Notifications + +
+
@@ -251,11 +246,16 @@ const MetricCard = ({ ); }; -const numberValue = (num: number) => num > 0 ? `+${num}` : '0'; +const numberValue = (num: number) => (num > 0 ? `+${num}` : "0"); function Analytics() { - const { data: analytics, isLoading, error, isError } = useSuspenseQuery(getAnalytics); - console.log({ analytics, isLoading, isError, error}) + const { + data: analytics, + isLoading, + error, + isError, + } = useSuspenseQuery(getAnalytics); + console.log({ analytics, isLoading, isError, error }); const byteValueNumberFormatter = Intl.NumberFormat("en", { notation: "compact", style: "unit", @@ -270,8 +270,7 @@ function Analytics() {
); - if (!analytics) return - + if (!analytics) return ; return (
diff --git a/src/lib/api/index.ts b/src/lib/api/index.ts index e9b1510..32d3a04 100644 --- a/src/lib/api/index.ts +++ b/src/lib/api/index.ts @@ -278,20 +278,14 @@ export const getAnalytics = queryOptions({ }, staleTime: 60 * 1000 }); -// return { -// "newUsersInLast30Days": 5, -// "newUsersInLast7Days": 2, -// "newUsersToday": 0, -// "newNodesInLast30Days": 2292, -// "newNodesInLast7Days": 454, -// "newNodesToday": 0, -// "activeUsersToday": 1, -// "activeUsersInLast7Days": 11, -// "activeUsersInLast30Days": 17, -// "nodeViewsToday": 2, -// "nodeViewsInLast7Days": 3485, -// "nodeViewsInLast30Days": 14245, -// "bytesToday": null, -// "bytesInLast7Days": 22890864, -// "bytesInLast30Days": 77358695 -// } + +export const validateAuth = queryOptions({ + queryKey: [], + queryFn: async () => { + const response = await fetch(`${NODES_API_URL}/v1/auth/check`, { + credentials: "include", + }); + const json = (await response.json()) as { ok: boolean }; + return json.ok || false; + }, +});