Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added new SessionChecker that guards the session is not started in th…
…e FE API
- Loading branch information
1 parent
a7b918b
commit 3d27fa3
Showing
2 changed files
with
27 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
packages/frontend-api/src/Component/SessionChecker/SessionChecker.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Shopsys\FrontendApiBundle\Component\SessionChecker; | ||
|
||
use Symfony\Component\HttpKernel\Event\ResponseEvent; | ||
|
||
class SessionChecker | ||
{ | ||
/** | ||
* @param \Symfony\Component\HttpKernel\Event\ResponseEvent $event | ||
*/ | ||
public function onKernelResponse(ResponseEvent $event): void | ||
{ | ||
$request = $event->getRequest(); | ||
if (!$request->hasSession() || !$request->getSession()->isStarted() || !str_contains($request->getRequestUri(), 'graphql')) { | ||
return; | ||
} | ||
$response = $event->getResponse(); | ||
$response->setContent('Session must not be started in the FE API. Check your code, please'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters