mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-29 16:14:43 +00:00
Dashboard & Error Login Message
This commit is contained in:
9
app/dashboard/Dashboard.tsx
Normal file
9
app/dashboard/Dashboard.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
"use client";
|
||||
export default function Dashboard() {
|
||||
return (
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-primary">Dashboard</h1>
|
||||
<p>Welcome to your dashboard</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
47
app/dashboard/page.tsx
Normal file
47
app/dashboard/page.tsx
Normal file
@@ -0,0 +1,47 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import Cookies from "js-cookie";
|
||||
import { useRouter } from "next/navigation";
|
||||
import Dashboard from "./Dashboard"
|
||||
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 ? <Dashboard /> : null;
|
||||
}
|
||||
Reference in New Issue
Block a user