fix: cache CSRF token in View to prevent mismatch on multiple renders
This commit is contained in:
@@ -10,6 +10,7 @@ class View
|
||||
private string $layout = 'main';
|
||||
private array $data = [];
|
||||
private Security $security;
|
||||
private ?string $csrfTokenCache = null;
|
||||
|
||||
public function __construct(Security $security)
|
||||
{
|
||||
@@ -80,7 +81,10 @@ class View
|
||||
|
||||
public function csrfToken(): string
|
||||
{
|
||||
return $this->security->generateCSRFToken();
|
||||
if ($this->csrfTokenCache === null) {
|
||||
$this->csrfTokenCache = $this->security->generateCSRFToken();
|
||||
}
|
||||
return $this->csrfTokenCache;
|
||||
}
|
||||
|
||||
public function csrfField(): string
|
||||
|
||||
Reference in New Issue
Block a user