mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
feat: unset cookie when logout
This commit is contained in:
@@ -4,12 +4,19 @@ namespace App\Controller;
|
||||
|
||||
use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Routing\RouterInterface;
|
||||
|
||||
class HomeController extends AbstractController
|
||||
{
|
||||
|
||||
public function __construct(private readonly RouterInterface $router)
|
||||
{
|
||||
}
|
||||
|
||||
#[Route(path: "/", name: "index")]
|
||||
public function index(): Response
|
||||
{
|
||||
@@ -21,4 +28,14 @@ class HomeController extends AbstractController
|
||||
{
|
||||
return $clientRegistry->getClient('oauth')->redirect();
|
||||
}
|
||||
|
||||
#[Route(path: "/logout", name: "logout")]
|
||||
public function logout(Security $security): ?RedirectResponse
|
||||
{
|
||||
$response = new RedirectResponse($this->router->generate('index'));
|
||||
$response->headers->clearCookie('BEARER');
|
||||
if ($security->isGranted('IS_AUTHENTICATED')) $security->logout(false);
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user