From 56430c09c55b45b2eedbd41f38af6de11e103868 Mon Sep 17 00:00:00 2001 From: Samuel Gfeller Date: Fri, 24 Nov 2023 19:16:15 +0100 Subject: [PATCH] Added session lifetime config [SLE-192] --- config/container.php | 6 ------ config/env/defaults.php | 5 +++-- config/middleware.php | 3 +-- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/config/container.php b/config/container.php index f84a9140..b8ee3a67 100644 --- a/config/container.php +++ b/config/container.php @@ -8,7 +8,6 @@ use Monolog\Handler\RotatingFileHandler; use Monolog\Logger; use Nyholm\Psr7\Factory\Psr17Factory; -use Odan\Session\Middleware\SessionStartMiddleware; use Odan\Session\PhpSession; use Odan\Session\SessionInterface; use Odan\Session\SessionManagerInterface; @@ -150,14 +149,9 @@ SessionInterface::class => function (ContainerInterface $container) { $options = $container->get('settings')['session']; - return new PhpSession($options); }, - SessionStartMiddleware::class => function (ContainerInterface $container) { - return new SessionStartMiddleware($container->get(SessionInterface::class)); - }, - BasePathMiddleware::class => function (ContainerInterface $container) { return new BasePathMiddleware($container->get(App::class)); }, diff --git a/config/env/defaults.php b/config/env/defaults.php index 2032fe57..55d6d8eb 100644 --- a/config/env/defaults.php +++ b/config/env/defaults.php @@ -153,8 +153,9 @@ // Session $settings['session'] = [ - 'name' => 'webapp', - 'cache_expire' => 0, + 'name' => 'slim-example-project', + // 5h session lifetime + 'lifetime' => 18000, // Time in seconds ]; $settings['logger'] = [ diff --git a/config/middleware.php b/config/middleware.php index ae1f0887..b82ed911 100644 --- a/config/middleware.php +++ b/config/middleware.php @@ -27,8 +27,7 @@ // but after PhpViewExtensionMiddleware as it needs the user id) $app->add(\App\Application\Middleware\UserNetworkSessionDataMiddleware::class); - // Has to be after PhpViewExtensionMiddleware to be called before on request as session is used in php-view extension - // LocaleMiddleware the same, session has to be established. All middlewares that need session must go above this line + // Has to be after every middleware that needs a started session (LIFO) $app->add(SessionStartMiddleware::class); // Cors middleware has to be before routing so that it is performed after routing (LIFO)