Symfony 4.4 get the logged in user before logging out

I need to get the current user before logging out to make some modifications to it.

This is what I have:

Security.yml:

security:
...

    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false
        api:
            pattern:   ^/api
            anonymous: true
            stateless: true
            guard:
                authenticators:
                    - lexik_jwt_authentication.jwt_token_authenticator
        main:
            anonymous: ~
            logout:
                path: /logout
                delete_cookies: ['rhsso', 'rhsso_refresh']
                success_handler: logout_success_handler
                handlers: [logout_handler]

Services.yml:

services:
    ...
    logout_success_handler:
        class: AppHandlerLogoutSuccessHandler

    logout_handler:
        class: AppHandlerLogoutHandler

But in the LogoutHandler the user is anonymous:

class LogoutHandler implements LogoutHandlerInterface
{
    (....)

    /**
     * This method is called by the LogoutListener when a user has requested
     * to be logged out. Usually, you would unset session variables, or remove
     * cookies, etc.
     */
    public function logout(Request $request, Response $response, TokenInterface $token)
    {
        $this->logger->info($token->getUser()); // <-- Log INFO: anon. []
    }
}

How can I get the current user here?

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *