AWS API Gateway sending 403 error on OPTIONS request for GET api call using fetch with below details from fiddler:
HTTP/1.1 403 Forbidden
Date: Fri, 23 Sep 2022 11:50:57 GMT
Content-Type: application/json
Content-Length: 42
Connection: keep-alive
x-amzn-RequestId: 02883556-5b3b-4af7-8c3a-3d561f2e0557
x-amzn-ErrorType: MissingAuthenticationTokenException
x-amz-apigw-id: Y6WFM7rPEF9iQ=
{"message":"Missing Authentication Token"}
While same url works fine with Axios request with exact request details verified by fiddler.
Fetch request was missing mode property, it defaults to no-cors that does not allow option request, setting mode to cors worked.
return fetch(`${process.env.URL}edit_session/${documentId}?${new URLSearchParams({
edit_token: editToken,
action: 'clear'
})}`, {
method: 'GET',
keepalive: true,
headers,
mode: 'cors',
cache: 'no-cache'
});