mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-19 00:17:01 +00:00
Dashboard Page authentication
This commit is contained in:
parent
79a4c1199a
commit
defc4e2f5e
9
app/dashboard/DashboardPage.tsx
Normal file
9
app/dashboard/DashboardPage.tsx
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
|
||||||
|
|
||||||
|
export default function DashboardPage() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h1>Dashboard</h1>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
37
app/dashboard/page.tsx
Normal file
37
app/dashboard/page.tsx
Normal file
@ -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 <Loading />;
|
||||||
|
} else {
|
||||||
|
return <DashboardPage />;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user