fix: cache CSRF token in View to prevent mismatch on multiple renders

This commit is contained in:
2026-06-14 09:03:53 -04:00
parent 4ce6b27f96
commit 12ad0e0510

View File

@@ -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