Reputation: 47
namespace App\Controller\SecurityController;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\Routing\Attribute\Route;
class SecurityController
{
#[Route(path: '/logout', name: 'logout')]
public function someAction(Security $security): Response
{
$response = $security->logout();
return $this->redirectToRoute('login');
}
}
Twig
<a href="{{ path('logout', {'token' : csrf_token('logout')}) }}">
Security
security:
enable_authenticator_manager: true
main:
lazy: true
provider: app_user_provider
form_login:
check_path: login
login_path: login
enable_csrf: true
default_target_path: /admin
remember_me:
secret: '%kernel.secret%' # required
lifetime: 2592000 # 1 month in seconds
I get it from documentation Symfony 6.4 but faced with error
Unable to logout with CSRF token validation.
What wrong? I don`t want disable CSRF protection.
Upvotes: 0
Views: 79