Javascript fetch api is not resolving in success or error

I am building a react native app, where I am using a fetch api to get the login response. The code snippet looks as below :

 export function login(username, password) {

    const url = `${baseUrl}/login`;
    const usernamePassword = `${username}:${password}`;
    const encodedString = Buffer.from(usernamePassword).toString('base64');
    console.log('encoded : ', encodedString);

    return fetch(url, {
        headers: {
            'Authorization': `Basic ${encodedString}`,
            'Cache-Control': 'no-cache'
        }
    }).then(resp => {
        console.log(resp);
    }).catch(err => {
        console.log(err)
    });
}

I tried a lot of things, but the last logger which gets printed is :

    console.log('encoded : ', encodedString);

No matter what I try its never printing the loggers added in then or catch.

a few observations :

  • if I remove the Authorization header, its start working fine (getting exception)
  • I am using a sprint-boot backend service and CORS is disabled in that
  • I tried hitting the same request with postman and I could get a 401 response code

Can someone please help resolving this.