CoreControl/app/page.tsx

40 lines
895 B
TypeScript
Raw Normal View History

2025-05-17 15:37:25 +02:00
"use client";
import LoginPage from "./LoginPage";
import Loading from "@/components/Loading";
2025-05-17 12:35:02 +02:00
import { useState, useEffect } from "react";
2025-05-17 15:37:25 +02:00
import { useRouter } from "next/navigation";
import axios from "axios";
2025-05-17 17:41:38 +02:00
import Cookies from "js-cookie";
2025-05-17 15:37:25 +02:00
2025-05-17 15:38:56 +02:00
export default function Login() {
2025-05-17 15:37:25 +02:00
const router = useRouter();
const [loading, setLoading] = useState(true);
2025-05-17 15:37:25 +02:00
useEffect(() => {
const init = async () => {
2025-05-19 21:41:46 +02:00
await axios.get("/api/user/init").then((response) => {
if(response.data.message === "No users found") {
router.push("/setup");
} else {
setLoading(false);
}
2025-05-19 16:51:32 +02:00
}).catch((error) => {
console.error(error);
});
2025-05-17 15:37:25 +02:00
};
init();
2025-05-17 17:41:38 +02:00
const token = Cookies.get("token");
if(token){
router.push("/dashboard");
}
2025-05-17 15:37:25 +02:00
}, []);
2025-05-17 15:22:03 +02:00
if (loading) {
return <Loading />;
} else {
return <LoginPage />;
}
}