import React, { useState } from 'react'; import axios from 'axios'; const AuthForm = ({ type = "login" }) => { const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const [msg, setMsg] = useState(''); const handleSubmit = async (e) => { e.preventDefault(); try { const endpoint = type === 'signup' ? '/signup' : '/login'; const res = await axios.post(`https://your-hf-space.hf.space${endpoint}`, { username, password, }); if (type === 'login') { localStorage.setItem('token', res.data.token); window.location.href = "/search"; } else { setMsg("Account created! You can now login."); } } catch (err) { setMsg(err.response?.data?.message || 'Something went wrong'); } }; return (

{type === 'signup' ? 'Sign Up' : 'Login'}

setUsername(e.target.value)} required /> setPassword(e.target.value)} required /> {msg &&

{msg}

}
); }; export default AuthForm;