Symfony - Mapping Exception - The class 'PreAuthenticatedToken' was not found in the chain configured namespaces App\Entity

241 Views Asked by At

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.

1

There are 1 best solutions below

0
ehymel On

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);

Related Questions in MAPPINGEXCEPTION