/** @jsx h */ import { h } from "preact"; import { useState, useEffect } from "preact/hooks"; export default function LoginFrame() { const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const checkUserLogin = async () => { const resp = await fetch("/api/user/login"); const respJson = await resp.json(); if (respJson.success) { // Redirect to main page if valid location.href = "/"; return true; } return false; }; const doUserLogin = async () => { const resp = await fetch("/api/user/login", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ email, password, }), }); const respJson = await resp.json(); if (respJson.success) { location.href = "/"; return true; } return false; }; useEffect(() => { checkUserLogin(); }, []); const onSubmit = () => { if (email && password) { doUserLogin(); } }; return (