There's a simple function auth
within the PHP trait InjectAuthTrait
. This trait requires an instance of JWTTokenManagerInterface
to be accessible within the class scope.
class OrderController extends AbstractController
{
use InjectAuthTrait;
public function __construct(
protected JWTTokenManagerInterface $JWTTokenManager,
) {}
Then you only have to wrap the array passed to the view through the render
function with the function auth
.
return $this->render('restaurant/index.html.twig', $this->auth([
'restaurant' => $order->getRestaurant(),
]));
The following script is loaded when the auth function is called on a view. It provides a basic retry mechanism in case the token expires.
The script inject inside the window context an object that contain:
true
is the user is connected.null
if no user logged.https://github.com/coopcycle/coopcycle-web/blob/e785a97e0d0fe3081eaaf4642175d24cf4ea8117/js/app/user/user-data.js
Here is a basic usage of httpClient, which has a method for each HTTP verb.