From 426a907c09a9735bcea8bd54ef1d47d42186cd49 Mon Sep 17 00:00:00 2001 From: Sebastian Helzle Date: Tue, 18 Apr 2023 10:35:03 +0200 Subject: [PATCH] BUGFIX: Prevent error when security context is initialised but no account is active --- Classes/PrunnerApiService.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Classes/PrunnerApiService.php b/Classes/PrunnerApiService.php index 1f805b9..26cc522 100644 --- a/Classes/PrunnerApiService.php +++ b/Classes/PrunnerApiService.php @@ -114,7 +114,8 @@ public function apiCall(string $method, string $subpath, ?string $body): Respons // There are usecases where we want to call prunner from the CLI. We don't have an initialized user there, thus we // hardcode it to 'cli' in these cases. The account identifier in prunner is only used for e.g. log messages. - $accountIdentifier = $this->context->isInitialized() ? $this->context->getAccount()->getAccountIdentifier() : 'cli'; + $account = $this->context->isInitialized() ? $this->context->getAccount() : null; + $accountIdentifier = $account ? $account->getAccountIdentifier() : 'cli'; // Generate JWT token on the fly with expiration in 60 seconds $authToken = JWT::encode(['sub' => $accountIdentifier, 'exp' => time() + 60], $jwtSecret, 'HS256'); $client = new Client();