Next.js Discord

Discord Forum

Random unexplained failed fetch

Unanswered
Highlander posted this in #help-forum
Open in Discord
HighlanderOP
I'm sending some data to my backend and for no apparent reason the fetch fails
  async function onSubmit(values: z.infer<typeof formSchema>) {
    const response = await fetch("http://localhost:8080/user/login", {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        "Accept": "application/json"
      },
      body: JSON.stringify({
        username: values.username,
        password: values.password,
      }),
    });
    if (!response.ok) {
      toast({
        description: response.json(),
      })
    }
    toast({
      description: "Login was successful",
    });
  }

3 Replies