mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-18 07:56:57 +00:00
37 lines
815 B
TypeScript
37 lines
815 B
TypeScript
"use client";
|
|
|
|
import LoginPage from "./LoginPage";
|
|
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 Login() {
|
|
const router = useRouter();
|
|
const [loading, setLoading] = useState(true);
|
|
|
|
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);
|
|
}
|
|
};
|
|
init();
|
|
|
|
const token = Cookies.get("token");
|
|
if(token){
|
|
router.push("/dashboard");
|
|
}
|
|
}, []);
|
|
|
|
if (loading) {
|
|
return <Loading />;
|
|
} else {
|
|
return <LoginPage />;
|
|
}
|
|
} |