import {useAuth} from "Frontend/util/auth"; import {useLayoutEffect, useState} from "react"; import {XCircle} from "@phosphor-icons/react"; import {Button, Card, CardBody, CardHeader, Input, Link} from "@nextui-org/react"; import {Alert, AlertDescription, AlertTitle} from "Frontend/@/components/ui/alert"; import {useNavigate} from "react-router-dom"; 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(); useLayoutEffect(() => { if (state.user) { const path = url ? new URL(url, document.baseURI).pathname : '/' navigate(path, {replace: true}); } }, [state.user]); return (
Gameyfin Logo {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?
); }