2

I would like to implement the logout action on my Symfony project.

At the moment, when I make the logout action, I receive the exception

controller can be blank: it will never be executed!. 

I've digged into internet and Symfony docs, normally this endpoint controller is never reached.

In my context,i can't logout and i don't know why this logout function is executed.

this is my configuration SecurityController.php

/**
 * @Route("/logout", name="app_logout", methods={"GET"})
 */
public function logout()
{
    // controller can be blank: it will never be executed!
    throw new \Exception('controller can be blank: it will never be executed!');
}

security.yaml

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

main:
    anonymous: ~
    pattern:  /login
    provider: app_user_provider
    guard:
        authenticators:
            - App\Security\LoginFormAuthenticator
    logout:
        path: app_logout
        # where to redirect after logout
        target: app_login

Have a nice day!

Mikhail Prosalov
  • 4,155
  • 4
  • 29
  • 41

2 Answers2

0

You placed the logout listener in the "main" firewall, but the logout url is not covered by the pattern. So the request of "/logout" will not run thru it. You might place the logout listener into that firewall which covers the logout url or modify the "main" firewall's pattern to include the logout url. The latter looks like this:

# config/packages/security.yaml
firewalls:
  main:
    # ...
    pattern: ^/(login|logout)$
    # ...
GT.
  • 91
  • 6
-1

Read the documentation.

To enable logging out, activate the logout config parameter under your firewall.

# config/packages/security.yaml
firewalls:
  main:
    # ...

    logout:
      path:   app_logout
      # where to redirect after logout
      # target: app_any_route

Next, you'll need to create a route for this URL (but not a controller).

# config/routes.yaml
app_logout:
  path: /logout
  methods: GET
Reqven
  • 1,688
  • 1
  • 8
  • 13