Despite of all the other questions on stack-overflow I was not able to resolve the issue with all the provided information.
That's why I decided to create a new one.
So I am implementing the remember me function in my login form with a checkbox that looks the like this:
<input type="checkbox" id="form_saveCredentials" name="form[saveCredentials]">
On login everything looks fine and the cookie gets set correctly
Through the whole browser session the cookie remains alive.
But when I close the browser and reopen it the cookie is still there (did not navigate to my localhost yet!).
When I navigate to my website on localhost the cookie gets deleted according to the response header
I have no idea why the cookie gets deleted on the navigation to the website.
Maybe the problem lies in the securtiy.yml settings for the remember_me functionality
firewalls:
somefirewall:
form_login:
remember_me: true
remember_me:
key: %secret%
lifetime: 31536000
remember_me_parameter: 'form[saveCredentials]'
path: /
domain: ~
Any idea on how to fix this problem? Thanks in advance
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!