LexikJWTAuthenticationBundle: Get current user on server side
Advice for you, use container key in controller.
Of course, it's better to send the your error here!
Symfony 4
protected function getCurrentUser() { if (!$this->container->has('security.token_storage')) { throw new \LogicException('The Security Bundle is not registered in your application.'); } if (null === $token = $this->container->get('security.token_storage')->getToken()) { return; } if (!is_object($user = $token->getUser())) { // e.g. anonymous authentication return; } return $user; }
I was having the same issue, you can get Id of current user by using :
$current_user = $this->getUser();$id = $current_user->getId();
Inside your controller.