0

I'm trying to access an API with a token, and I need to pass in X-Auth-Token in the header with the value being my token but I keep getting a CORS error

import axios from 'axios';
import React, { useEffect } from 'react';

function LeagueTable() {
  const api = 'https://api.football-data.org/v4/teams/19';

  axios.get(api, {
    headers: {
      'X-Auth-Token': '****',
    },
  });

  return (
    <div>
    </div>
  );
}

export default LeagueTable;

The error is: 'No 'Access-Control-Allow-Origin' header is present on the requested resource.' and an uncaught promise - can anyone advise?

I've tried playing around with how I enter the header as a parameter but to no avail - however on POSTMAN, I can pass in X-Auth-Token with the token in the header and it returns fine

notmoot
  • 9
  • 2

1 Answers1

0

You should pass the token as part of your interceptors in the entry file of your project. It was answered here Attach Authorization header for all axios requests