Reviewed latest middleware optimizations

This commit is contained in:
Bernd Bestel 2026-08-16 18:43:27 +02:00
parent d941daae42
commit 4732f4a186
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
4 changed files with 7 additions and 8 deletions

View File

@ -13,14 +13,14 @@ class DefaultAuthMiddleware extends BaseAuthMiddleware
if ($this->IsApiRoute)
{
// Session cookie or API Key is ok
$auth = new ApiKeyAuthMiddleware($this->AppContainer, $this->ResponseFactory);
$auth = new SessionAuthMiddleware($this->AppContainer, $this->ResponseFactory);
$user = $auth->AuthenticateRequest($request);
if ($user !== null)
{
return $user;
}
$auth = new SessionAuthMiddleware($this->AppContainer, $this->ResponseFactory);
$auth = new ApiKeyAuthMiddleware($this->AppContainer, $this->ResponseFactory);
$user = $auth->AuthenticateRequest($request);
return $user;
}

View File

@ -12,7 +12,7 @@ class ReverseProxyAuthMiddleware extends BaseAuthMiddleware
{
define('GROCY_EXTERNALLY_MANAGED_AUTHENTICATION', true);
// When the reverse proxy is configured to be bypassed for API routes, try to use regular ApiKeyAuth
// Try to use regular API Key authentiaction (applies when the reverse proxy is configured to be bypassed for API routes)
if ($this->IsApiRoute)
{
$auth = new ApiKeyAuthMiddleware($this->AppContainer, $this->ResponseFactory);

View File

@ -15,7 +15,7 @@ class BaseMiddleware
$this->ApplicationService = ApplicationService::GetInstance();
}
protected $AppContainer;
protected $ResponseFactory;
protected $ApplicationService;
protected Container $AppContainer;
protected ResponseFactoryInterface $ResponseFactory;
protected ApplicationService $ApplicationService;
}

View File

@ -18,7 +18,7 @@ class LocaleMiddleware extends BaseMiddleware
private function GetLocale(Request $request)
{
// demo and prerelease modes are fixed to the default locale
// Demo and Prerelease modes are fixed to the default locale
if (GROCY_MODE === 'demo' || GROCY_MODE === 'prerelease')
{
return GROCY_DEFAULT_LOCALE;
@ -28,7 +28,6 @@ class LocaleMiddleware extends BaseMiddleware
if (defined('GROCY_AUTHENTICATED') && GROCY_AUTHENTICATED)
{
$locale = UsersService::GetInstance()->GetUserSetting(GROCY_USER_ID, 'locale');
if (isset($locale) && !empty($locale))
{
if (in_array($locale, scandir(__DIR__ . '/../localization')))