How to customize Logout target in Symfony 5.x

I want to force the redirection destination to a dynamically set route after a successful logout from a Symfony security session.

I tried to do it like

if ($this->isGranted('IS_AUTHENTICATED_FULLY')) {
    return $this->redirect($this->generateUrl('security_logout', [
        '_target_path' => $this->generateUrl('can_be_any_random_path')
    ]));
}

But the destination path is obviously ignored, because you are always redirected to the homepage. (As it is defined in security.yaml)

How can I overwrite the target dynamically?

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

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