import {useAuth} from "Frontend/util/auth"; import {useState} from "react"; import {Link, useNavigate} from "react-router-dom"; import {SpinnerGap, XCircle} from "@phosphor-icons/react"; import {Card} from "Frontend/@/components/ui/card"; import {Alert, AlertDescription, AlertTitle} from "Frontend/@/components/ui/alert"; import {Button} from "Frontend/@/components/ui/button"; import {Input} from "Frontend/@/components/ui/input"; export default function LoginView() { const {state, login} = useAuth(); const [hasError, setError] = useState(false); const [loading, setLoading] = useState(false); 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 (
{hasError && Error Wrong username and/or password }
{ e.preventDefault(); if (typeof username === "string" && password != null) { setLoading(true); const {defaultUrl, error, redirectUrl} = await login(username, password); if (error) { setError(true); } else { setUrl(redirectUrl ?? defaultUrl ?? '/'); } setLoading(false); } }} > { setUsername(event.target.value); }} id="username" type="text" autoComplete="username" placeholder="" /> { setPassword(event.target.value); }} id="current-password" type="password" autoComplete="current-password" placeholder="" />
Forgot password?
); }