@daisha
To stop Symfony from redirecting after logout, you can override the default logout success handler and customize the behavior. Here's how you can do it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
// src/Security/CustomLogoutSuccessHandler.php
namespace AppSecurity;
use SymfonyComponentHttpFoundationRedirectResponse;
use SymfonyComponentHttpFoundationRequest;
use SymfonyComponentSecurityHttpLogoutLogoutSuccessHandlerInterface;
class CustomLogoutSuccessHandler implements LogoutSuccessHandlerInterface
{
public function onLogoutSuccess(Request $request)
{
// Customize the behavior after logout
return new RedirectResponse('/custom-logout-page');
}
}
|
1 2 3 4 5 6 7 8 |
# config/packages/security.yaml
security:
firewalls:
main:
logout:
path: app_logout
success_handler: AppSecurityCustomLogoutSuccessHandler
|
1 2 3 4 5 |
# routes.yaml
app_logout:
path: /logout
controller: AppControllerCustomLogoutController::logout
|
With these changes, Symfony will no longer redirect to the homepage after logout and instead redirect to the specified custom logout page.