0

I am trying to consume a login endpoint and I am getting the error in my console has been blocked by CORS policy.

here is my function that handles login

async function loginUser(credentials) {
    return fetch('https://visbackend.herokuapp.com/auth/login', {
      method: 'POST',
      mode: 'cors',
      headers: {
         'Content-Type': 'application/json',
        // 'Access-Control-Allow-Origin': '*',
        // "Access-Control-Allow-Headers": "X-Requested-With"
        // 'Access-Control-Allow-Origin':  'http://127.0.0.1:3000',
        // 'Access-Control-Allow-Methods': 'POST',
        // 'Access-Control-Allow-Headers': 'Content-Type, Authorization'

      },
     
      body: JSON.stringify(credentials)
    })
      .then(data => data.json())
   }

i understand i am supposed to allow cors , but i have gone through every sample as you can see, i have some lines of code commented out , but the error still persists.

please what am i doing wrong, thanks in advance.

developia
  • 1
  • 1
  • CORS should be handled at server side - see this blog if it helps https://jakearchibald.com/2021/cors/ – KcH Dec 09 '22 at 07:07

0 Answers0