Symfony2 : remember me cookie gets deleted when reopening the browser Symfony2 : remember me cookie gets deleted when reopening the browser symfony symfony

Symfony2 : remember me cookie gets deleted when reopening the browser


I recently had this problem, and here is the solution I found:

The reason why the cookie is deleted is because the user information that the cookie contains doesn't match anything that Symfony knows about. It can't log a user in based on the cookie, so it just deletes it. The issue in my case was an incorrect string in my UserProvider class. The specific method is supportsClass. It was returning 'AppBundle\Security\User' when it should have actually been returning `'AppBundle\Entity\User'. This caused Symfony to be unable to find any users based on the information in the cookie, and then it would just delete the cookie and move on.

You can do some more troubleshooting if you go into this file: vendor/symfony/symfony/src/Symfony/Component/Security/Http/RememberMe/TokenBasedRememberMeServices.php. Play around in processAutoLoginCookie and see if you can't figure something out!

Good luck!


I had the same problem but was my fault: in LoginFormAuthenticator::onAuthenticationSuccess() I did not return RedirectResponse

    public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey){    if ($targetPath = $this->getTargetPath($request->getSession(), $providerKey)) {        return new RedirectResponse($targetPath);    }    // my error : new RedirectResponse($this->urlGenerator->generate('my_route_to_page'));    return  new RedirectResponse($this->urlGenerator->generate('my_route_to_page'));        //throw new \Exception('TODO: provide a valid redirect inside '.__FILE__);}

Once changed, I can login with username or email and the browser remember the cookie when I reopen again.


This problem can occur if your username is a valid e-mail but isn't equal to the e-mail. Remove any @ in usernames.