Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony 3.1: Unable to find the controller for path "/logout"

I am trying to get my logout functionality done using Symfony 3.1, but it has not working so far. I am following the book documentation step by step but all I am getting is a not found exception:

Unable to find the controller for path "/logout". The route is wrongly configured.

I do activate the correct config parameter (logout) in the security.yml file

security:
       firewalls:
        # disables authentication for assets and the profiler, adapt it according to your needs
            dev:
                pattern: ^/(_(profiler|wdt)|css|images|js)/
                security: false

            main:
                anonymous: ~
                # activate different ways to authenticate
                form_login:
                    login_path: login
                    check_path: login
            secured_area:
                anonymous: ~
                logout:
                    path:   /logout
                    target: /

And I do create a route inside routing.yml:

logout:
    path: /logout

And that's it according the documentation, no controller is needed, but the exceptions says that controller path is wrong.

What am I doing wrong?

like image 590
Jotaeme Avatar asked Mar 11 '23 16:03

Jotaeme


2 Answers

I think it is because you have two firewalls defined. For the moment, get rid of the secured_area stuff and try something like:

firewalls:
    dev:
        pattern: ^/(_(profiler|wdt)|css|images|js)/
        security: false

    main:
        pattern:  ^/
        anonymous: ~
        switch_user: true

        form_login:
            provider:            user_provider
            login_path:          user_login
            check_path:          user_login_check
            default_target_path: app_welcome

            username_parameter:  username
            password_parameter:  password

            csrf_parameter:       _csrf_token
            csrf_token_id:        authenticate
            csrf_token_generator: security.csrf.token_manager

        logout:
            path:   user_logout
            target: app_welcome

Notice that the logout section is under the main firewall. Once you have the main firewall working then you can try adding the secured_area back in if you really need it.

And yes I got lazy and just copied/pasted a working configuration. You will have to tweak the routes to match yours.

like image 146
Cerad Avatar answered Mar 19 '23 10:03

Cerad


Thanks for top answer which is right. There is another trick you should be aware of: Make sure that /logout is behind a firewall. /logout path has to match a firewall pattern.

Ex: 'pattern: ^/admin' then logout path should be '/admin/logout'.

like image 32
yakob abada Avatar answered Mar 19 '23 12:03

yakob abada