-
Notifications
You must be signed in to change notification settings - Fork 32
Using withCredentails in Axios For WC Cookies
Imran Sayed edited this page Oct 2, 2021
·
2 revisions
If your frontend domain is the same as backend, then you can use withCredentials in axios and then it will automatically set the cookie on client side and send it with subsequent request. But in that case you need to add this function to your WordPress, to ensure that SameSite is set to none while WordPress sets the cookie. This is required for cross domain only
* Adds the COOKIEPATH constant with SameSite=None
*
* This is to allow the cookies to be set on the frontend application,
* if the frontend application is on a different domain, else you they
* don't get set because of cross-domain. This is required for cart session functionality.
*
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite#samesitenone_requires_secure
*/
if ( ! defined( 'COOKIEPATH' ) ) {
define( COOKIEPATH, '/;SameSite=None' );
}```