You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#[CurrentUser]: Cannot autowire argument $user of "App\Controller\FooController::method()": it references class "App\Entity\User" but no such service exists if user isn't logged in #45257
If I try to autowire \App\Entity\User to a non-nullable variable using #[CurrentUser] attribute in a controller method and I'm not logged in, Symfony crashes with a RuntimeException $user references class "App\Entity\User" but no such service exists.
It works like a charm if I logged in or the variable is nullable.
I'd expect it throws \Symfony\Component\Security\Core\Exception\AccessDeniedException instead, because if a programmer requests a non-null $user for a method then I think there's is an implication this method is accessible only if a user is logged in (as if there's a $this->denyAccessUnlessGranted('IS_AUTHENTICATED_REMEMBERED'); line in the beginning).