(Symfony)Fix the login Invalid credentials error in prod env

in Shares with 0 comment

This error is very weird.
The login function works normally in the dev environment but always fails with the Invalid credentials when deployed on the prod environment.
There are only few similar questions on the stackoverflow and none of them provide the correct solution or the advice is out of date(Only works for the old version Symfony)

The potential fix solution:
Add save_path: "%kernel.cache_dir%/sessions/%kernel.environment%" in the config/framework.yaml session section part.

framework:
    secret: '%env(APP_SECRET)%'
    #csrf_protection: true
    #http_method_override: true

    # Enables session support. Note that the session will ONLY be started if you read or write from it.
    # Remove or comment this section to explicitly disable session support.
    session:
        save_path: "%kernel.cache_dir%/sessions/%kernel.environment%"
        handler_id: null
        cookie_secure: auto
        cookie_samesite: lax

    #esi: true
    #fragments: true
    php_errors:
        log: true

Remember to grant permission for those folders.
sudo chown -R www:www /www/wwwroot/project/var/cache

Responses