Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integrating Symfony security and other template utilities with ReactJS

I have working application on symfony with twig template engine. It is very usefull to have app.request and app.user objects and utils like is_granted('ROLE_MODER') in template. Is there way for handling all this in react js? For example for routes i think i could use FOS JsRouting bundle, but i couldn't find any opportunity how could i access app object or granting function in react js.

like image 571
kRicha Avatar asked Jun 08 '17 21:06

kRicha


1 Answers

You could struct your application using HATEOAS:

https://github.com/willdurand/Hateoas

and also a REST bundle

http://symfony.com/doc/current/bundles/FOSRestBundle/index.html

Finally, to keep everything in security you can work with symfony's Voter/or ACL:

http://symfony.com/doc/current/security/voters.html

and keep all the control you need.

If you want to tell symfony information to reactjs, just create an endpoint for this. If you want to build a react component that handle with symfony's part, build it using twig.

But I suggest you to consider your symfony part as a REST API. I mean, ... you are just talking with an API. Your ReactJs client should never know that that API is written in Symfony.

like image 97
sensorario Avatar answered Oct 12 '22 22:10

sensorario