Skip to content
Advertisement

API Plateform custom get operation

I am trying to build an ecommerce site using API plateform.

Since I am using JWT authentication with LexikJWTAuthenticationBundle I am having a hard time to get the user with the token.

I would like to access the cart of the user.

I managed to add to the cart through a custom post operation.

JavaScript

I am trying to use the same way but with a get request

JavaScript
JavaScript

Any idea what I am doing wrong?

Advertisement

Answer

Instead using a controller, have you try to use custom DataProvider and inject Security ?

JavaScript

$this->security->getUser() will return your user and $this->security->getToken() will return all about your token

Here’s the documentation: https://api-platform.com/docs/core/data-providers/#custom-item-data-provider

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement