IMHO the best option is to implement the LogoutHandlerInterface
referenced slightly indirectly on the symfony docs you mentioned (it mentions the LogoutSuccessHandlerInterface
, which has a comment regarding the LogoutHandlerInterface
: "If you want to only perform some logout related clean-up task, use the LogoutHandlerInterface instead.")
To me, it feels like an event handler, but it doesn't use the event system, so ... whatever.
Nevertheless, the arguments provided to your LogoutHandler
will receive a TokenInterface
which has TokenInterface::getUser()
which returns the current user. (dependency injection on the constructor should provide you with additional services and stuff)
The alternative would be to implement an EventListener for the kernel request event - which the LogoutListener
of the symfony/security
package uses to manage logouts. You would have to add the same logic as the LogoutListener
and probably have to make it trigger before the LogoutListener
, this is however a slightly more convoluted way and I would really use the LogoutHandler
.