Whenever a successful login occurs, I want to redirect the user to a different page. However, I am encountering an error message:
https://i.sstatic.net/Wi8XW.png
This is the snippet of code that is causing the issue:
export default function SignUp() {
const trigger = async (event: any) => {
event.preventDefault();
const data = new FormData(event.currentTarget);
const navigate = useNavigate();
try {
const response = await fetchRestEndpoint(`/users`, 'POST', {
username: data.get("username"),
email: data.get("email"),
password: data.get("password"),
role: "user"
});
if (response.ok) {
const user: any = await response.json();
console.log(user);
navigate('/');
}
} catch(e) {
alert(e);
}
......