JavaScript fetch api: TypeError failed to fetch

I'm creating a blog with a friend as a small project between us. I'm and tested the backend in PHP, he's writing the frontend code. As he is still newer than me HTML and JS, I'm also writing the JS code to handle comms with the backend. The issue we're facing and can't get our heads around is the following: Logging in is possible with username or email and the password. The login code works when

  1. Username - password with curl
  2. Email - password with curl
  3. Username - password with Postman
  4. Email - password with Postman
  5. Username - password with vanilla JS fetch

What doesn't work is the Email - password with vanilla JS fetch. In this case we get the TypeError: Load failed or Failed to fetch. This is the JS code:

    
        const credential = document.getElementById('email').value;
        const password = document.getElementById('password').value;
        const body = JSON.stringify({ credential, password });
    
            fetch('/api/auth/login', { method: 'POST', body: body, headers: { 'Content-Type': 'application/json; charset=UTF-8' } })
                .then((res) => res.json())
                .then((data) => {
                    if (data.access_token) {
                        localStorage.setItem('fit_token', data.access_token);
                    } else {
                        alert(data.message);
                    }
                })
                .catch((err) => console.log(err));
    };

The catch isn't even reached, nothing gets logged in console. I only see the error when I debug...

Can anyone point us in the right direction?

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum