'How to prevent sending cookies from UI using react to backend for selective apis

In our application , there are certain cookies related to analytics etc which are being sent as part of every request api from frontend, we are not explicity setting any cookies from frontend as part of any request.

Due to certain scenarios the cookie size is becoming large and in turn increasing the size of header, we have increased the size of header as well, but still we receive the 413 error code or at times 400 with no response(request size is too large)

we have tried with axios setting withCredentials to false and with fetch setting credentials:'omit' we still see the credentials:'include' when we use the request as copy as fetch

Is there a way to prevent sending cookies from frontend for selective api request, the application is using react in frontend



Solution 1:[1]

You can try axios request Interceptors, they allow you to run arbitrary code for each request and modify the payload/headers and all kinds of things. Possibly cookies too.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 v1adko