Rectangle 27 0

"You cannot refresh a user from the EntityUserProvider that does not contain an identifier. The user object has to be serialized with its own identifier mapped by Doctrine."

This is not the answer to the question, but if someone googles the error message above (like I did) this is the top hit. And since I found my solution, I thought I'd share.

You will get this error if you remove the current user from the database and then try to redirect the user. (Which might seem like a silly mistake, but the error message sure isn't helping!) The solution is to simply clear out the session before you redirect.

$this->get('security.context')->setToken(null);
$this->get('request')->getSession()->invalidate();

Thank you! I had that exact problem; removed user entity and tried to re-direct to login page and got the error above. Googled the error message and, voila! Landed here! You're effort saved me a ton more.

php - Getting "cannot refresh user" error with symfony2 and doctrine -...

php symfony2 doctrine2