I am trying to programmatically logout the current user from inside a listener. I read here that
$this->get('security.context')->setToken(null); $this->get('request')->getSession()->invalidate(); does the trick but then I can't call $this->container->get('security.context')->getToken()->getUser(); anymore as the token is now NULL.
How can I log out the user but still let the application run normally? I have calls to getUser() in my controller functions so I should set back the token to something corresponding to an non authenticated user. How can I do this?
Also, if there is a way to programmatically start a new session and set a flash message to inform the user he has been logged out, it would be awesome.