mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-17 23:47:13 +00:00
47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect, useState } from "react";
|
|
import Cookies from "js-cookie";
|
|
import { useRouter } from "next/navigation";
|
|
import Servers from "./Servers"
|
|
import axios from "axios";
|
|
|
|
export default function DashboardPage() {
|
|
const router = useRouter();
|
|
const [isAuthChecked, setIsAuthChecked] = useState(false);
|
|
const [isValid, setIsValid] = useState(false);
|
|
|
|
useEffect(() => {
|
|
const token = Cookies.get("token");
|
|
if (!token) {
|
|
router.push("/");
|
|
} else {
|
|
const checkToken = async () => {
|
|
try {
|
|
const response = await axios.post("/api/auth/validate", {
|
|
token: token,
|
|
});
|
|
|
|
if (response.status === 200) {
|
|
setIsValid(true);
|
|
}
|
|
} catch (error: any) {
|
|
Cookies.remove("token");
|
|
router.push("/");
|
|
}
|
|
}
|
|
checkToken();
|
|
}
|
|
setIsAuthChecked(true);
|
|
}, [router]);
|
|
|
|
if (!isAuthChecked) {
|
|
return (
|
|
<div className="flex items-center justify-center h-screen">
|
|
<span className="loading loading-infinity loading-xl"></span>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
return isValid ? <Servers /> : null;
|
|
} |