import { useRef, useState } from 'react'; import { useRouter } from "next/router"; import MyAppBar from "../component/appBar"; import Grid from '@mui/material/Grid'; import Box from '@mui/material/Box'; import Card from '@mui/material/Card'; import TextField from '@mui/material/TextField'; import Button from '@mui/material/Button'; import Backdrop from '@mui/material/Backdrop'; import CircularProgress from '@mui/material/CircularProgress'; import { ToastContainer, toast, Zoom, Bounce } from 'react-toastify' import 'react-toastify/dist/ReactToastify.css'; import Swal from 'sweetalert2' import withReactContent from 'sweetalert2-react-content' const MySwal = withReactContent(Swal) // require("dotenv").config(); function HomePage() { const [backdrop, setBackdrop] = useState(false); const usernameInputRef = useRef(); const passwordInputRef = useRef(); const router = useRouter(); async function submitHandler(event) { event.preventDefault(); setBackdrop(true); try { const username = usernameInputRef.current.value; const password = passwordInputRef.current.value; let http_server = "/api/login_admin?username=" + username + "&password=" // console.log(http_server); const response = await fetch(http_server, { // timeout: 10000, method: 'GET', headers: { 'Content-Type': 'application/json', 'allow-cors-origin': '*', 'crossDomain': true, } }); const data = await response.json(); if (response.status === 200) { setBackdrop(false); MySwal.fire({ title: 'Login Success', text: 'You will be redirected to the admin page', icon: 'success', confirmButtonButton: false, timer: 2000 }) await router.push('/admin'); }else{ setBackdrop(false); MySwal.fire({ title: 'Login Failed', text: 'Please check your username and password', icon: 'error', confirmButtonButton: false, timer: 2000 }) } // setBackdrop(true); // // await 4 sec // await new Promise(resolve => setTimeout(resolve, 4000)); // toast.error("heheheh"); // setBackdrop(false); } catch (error) { console.log("error", error); } finally { setBackdrop(false); } // setBackdrop(true); } return (
theme.zIndex.drawer + 1 }}> {/* */}

Admin Login





{/*
*/}
); } export default HomePage;