Quantcast
Channel: Active questions tagged symfony4 - Stack Overflow
Viewing all articles
Browse latest Browse all 3925

Can't Logout user in Symfony4

$
0
0

I'm updating a project built with Symfony2.7 to Symfony4, everything is working fine and have good compatibility, but one thing that should be fine, a built-in resource, the security layer, doesn't work as expected.

The problem I'm facing is that I can't logout users anymore. I followed the steps on the guide but nothing changed.

Below is the security config:

#config/packages/security.yaml
security:
    encoders:
        App\Entity\Clients:
            algorithm: bcrypt

    providers:
        app_user_provider:
            entity:
                class: App\Entity\Clients
    firewalls:    
        app:
            pattern: ^/
            anonymous: ~
            provider: app_user_provider
            remember_me:
                secret: "%kernel.secret%"
            form_login:
                use_referer: true
                login_path: login
                check_path: login_check
                always_use_default_target_path: false
                default_target_path: dashboard
                csrf_token_generator: security.csrf.token_manager
            logout:
                path: logout
                target: home
                invalidate_session: false

The paths I'm using are route names, but also tried the path itself.

I can normally login any user, but when I hit the logout route, I'm just redirected to home route, but the user is still authenticated.

Tried to set a custom handler logout like:

logout:
    handlers: [logout_handler]

It references to a service implementing Symfony\Component\Security\Http\Logout\LogoutHandlerInterface, but it didn't even call the handler.

It would be great if I could only use the default handler, and it's necessary to maintain the "remember_me" behavior, which was also working fine in 2.7.

Could anyone help me with that?

EDIT: My config routes.yaml is empty, 'cause I'm using annotation routes, the config/packages/routing.yaml is as follows:

framework:
    router:
        strict_requirements: ~

Just like when initialized with the composer create-project command. And for the annotations config I have the file config/routes/annotations.yaml:

controllers:
    resource: ../../src/Controller/
    type: annotation

Again, it's the config the recipe created by itself.


Viewing all articles
Browse latest Browse all 3925

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>