1

I'm trying to logout my user, getting it's token (which is existing and working) like this:

public function logout(Request $request, TokenStorageInterface $tokenStorage)
    {
            $em = $this->get('doctrine.orm.entity_manager');
            $user = $this->getUser();
            $user->setConnected(false);
            $em->remove($tokenStorage->getToken()); // Error is here
            $em->persist($user);
            $em->flush();
    }

When I request this method, I get the folowing error:

The class 'Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken' was not found in the chain configured namespaces App\Entity

I tried to search on google and SO but didn't find any related thread, as this class is not an entity.

I tried to include a "use" statement on top of my controller, but that didn't do the trick.

What am I doing wrong ?

Thanks to anyone who will take the time to read or answer this.

Pierrick Martellière
  • 1,554
  • 3
  • 21
  • 42

1 Answers1

1

The error is that you are using doctrine's entity manager to do something with a token storage (which is a session cookie I think), and that of course is not an entity that doctrine would know anything about. Just remove your line

$em->remove($tokenStorage->getToken()); // <--- REMOVE

and instead do this:

$tokenStorage->setToken(null);
ehymel
  • 1,360
  • 2
  • 15
  • 24