CoreControl/app/page.tsx

37 lines
815 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 () => {
const response = await axios.get("/api/user/init");
if (response.data.message === "No users found") {
router.push("/setup");
} else {
setLoading(false);
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 />;
}
}