import { useState } from "react"; import { useNavigate, useLocation } from "react-router-dom"; import { toast } from "react-toastify" import useAuth from "../../auth/auth"; import FormField from "../../components/FormField" import "./login.css" const Login = () => { const { setToken } = useAuth(); const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); const navigate = useNavigate(); const location = useLocation(); const searchPath = new URLSearchParams(location.search); const redirectPath = searchPath.get("to") || "/"; const [usernameEmpty, setUsernameEmpty] = useState(false); const [passwordEmpty, setPasswordEmpty] = useState(false); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); setUsernameEmpty(!username); setPasswordEmpty(!password); if (!username || !password) { return; } // TODO: request to API - login if (username === "a" && password === "a") { const token = "todo.jwt.token"; setToken(token); navigate(redirectPath, { replace: true }); } else { toast.error("Wrong login or password"); } }; return (

Welcome to Picrinth Web-Admin!
Picrinth is an open source app for scrolling synchronized
feeds of pictures from different sources together with your friends
Enjoy [#]

Picrinth logo

setUsername(e.target.value)} required showError={usernameEmpty} errorMessage="Please enter your username" /> setPassword(e.target.value)} required showError={passwordEmpty} errorMessage="Please enter your password" />

Create account

Frontend

Backend

Author

); }; export default Login;