From defc4e2f5ec6218cd1ad2063b805b159f27efd56 Mon Sep 17 00:00:00 2001 From: headlesdev Date: Sat, 17 May 2025 17:38:03 +0200 Subject: [PATCH] Dashboard Page authentication --- app/dashboard/DashboardPage.tsx | 9 ++++++++ app/dashboard/page.tsx | 37 +++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 app/dashboard/DashboardPage.tsx create mode 100644 app/dashboard/page.tsx diff --git a/app/dashboard/DashboardPage.tsx b/app/dashboard/DashboardPage.tsx new file mode 100644 index 0000000..fce7d71 --- /dev/null +++ b/app/dashboard/DashboardPage.tsx @@ -0,0 +1,9 @@ + + +export default function DashboardPage() { + return ( +
+

Dashboard

+
+ ); +} \ No newline at end of file diff --git a/app/dashboard/page.tsx b/app/dashboard/page.tsx new file mode 100644 index 0000000..fbdc5a1 --- /dev/null +++ b/app/dashboard/page.tsx @@ -0,0 +1,37 @@ +"use client"; + +import DashboardPage from "./DashboardPage"; +import Loading from "@/components/Loading"; + +import { useState, useEffect } from "react"; +import { useRouter } from "next/navigation"; +import axios from "axios"; +import Cookies from "js-cookie"; + +export default function Dashboard() { + const router = useRouter(); + const [loading, setLoading] = useState(true); + + useEffect(() => { + const init = async () => { + const token = Cookies.get("token"); + if (!token) { + router.push("/"); + } + const response = await axios.post("/api/user/validate", { token }); + if (response.data.message !== "Valid") { + Cookies.remove("token"); + router.push("/"); + } else { + setLoading(false); + } + }; + init(); + }, []); + + if (loading) { + return ; + } else { + return ; + } +} \ No newline at end of file