I created a axios get request in javascript to my apigateway url.
const headers = { Authorization: 'Bearer ' + user.value, 'Accept': 'application/json' };
const response = await axios.get('MYAPI', { headers });
console.log(response);
It gives a 401 Unauthorized.
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://MYAPI.amazonaws.com/.... (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 401.
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://MYAPI.amazonaws.com/..... (Reason: CORS request did not succeed). Status code: (null).
But when I access this endpoint via Postman it gives the success result. In postman I enter the access token. The user.value
variable contains my access token. I know for sure the token is filled because I see it in my Authorization request header.
How can I get the same result as in postman? What am I doing wrong here?