import {useAuth} from "Frontend/util/auth"; import {useState} from "react"; import {useNavigate} from "react-router-dom"; import {Button, Card, Input, Typography} from "@material-tailwind/react"; export default function LoginView() { const {state, login} = useAuth(); const [hasError, setError] = useState(); const [username, setUsername] = useState(); const [password, setPassword] = useState(); const [url, setUrl] = useState(); const navigate = useNavigate(); if (state.user && url) { const path = new URL(url, document.baseURI).pathname; navigate(path, {replace: true}); } return (
{ e.preventDefault(); if (typeof username === "string" && password != null) { const {defaultUrl, error, redirectUrl} = await login(username, password); if (error) { setError(true); alert("Wrong username and/or password!"); } else { setUrl(redirectUrl ?? defaultUrl ?? '/'); } } }} > Username { setUsername(event.target.value); }} size="lg" className=" !border-t-blue-gray-200 focus:!border-t-gray-900" labelProps={{ className: "before:content-none after:content-none", }} crossOrigin="" //TODO: see https://github.com/creativetimofficial/material-tailwind/issues/427 /> Password { setPassword(event.target.value); }} type="password" size="lg" className=" !border-t-blue-gray-200 focus:!border-t-gray-900" labelProps={{ className: "before:content-none after:content-none", }} crossOrigin="" //TODO: see https://github.com/creativetimofficial/material-tailwind/issues/427 />
); }