How to set and send Cookies in Symfony while the front-end is in ReactJS?

I am programming an application that uses ReactJs for the front-end in localhost:3001 and Symfony for the back-end localhost:3000, and to enable cross origin communication I use “cors-bundle” in Symfony.
Now I want to create a Cookie when a user log in, but it doesn’t seem to be created !

Thanks for your help,

This is the code in Symfony the moment a user logs in :

use SymfonyComponentHttpFoundationCookie;


$cookie = new Cookie( 'my_cookie', 1, strtotime('tomorrow') );
$res = new Response();
$res->headers->setCookie( $cookie );
return new JsonResponse($res);

This what I also tried :

$res->headers->setCookie(Cookie::create('my_cookie', 1));
return new JsonResponse($res);

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *