Skip to content
This repository has been archived by the owner on Apr 17, 2024. It is now read-only.

Commit

Permalink
fix: start session in middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
darkalchemy committed Feb 18, 2020
1 parent 7574a26 commit df4ddef
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 11 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Slim-Auth
A Slim 4 Skeleton.

![GitHub commits since tagged version](https://img.shields.io/github/commits-since/darkalchemy/Slim-Auth/0.3.2)
![GitHub commits since tagged version](https://img.shields.io/github/commits-since/darkalchemy/Slim-Auth/0.3.3)
[![GitHub Issues](https://img.shields.io/github/issues/darkalchemy/Slim-Auth)](https://github.com/darkalchemy/Slim-Auth/issues)
[![GitHub license](https://img.shields.io/github/license/darkalchemy/Slim-Auth.svg)](https://github.com/darkalchemy/Slim-Auth/blob/master/LICENSE)
[![Total Downloads](https://img.shields.io/packagist/dt/darkalchemy/Slim-Auth.svg)](https://packagist.org/packages/darlachemy/slim-auth)
Expand All @@ -19,11 +19,12 @@ npm is required
[delight-im/PHP-I18N](https://github.com/delight-im/PHP-I18N) for generating the files needed for poedit
[jobby](https://github.com/jobbyphp/jobby) to run all background jobs through cron
[Eloquent/ORM](https://github.com/illuminate/database) for database storage
[EmailValidator](https://github.com/egulias/EmailValidator/tree/master) for validating emails
[EmailValidator](https://github.com/egulias/EmailValidator/tree/master) for validating emails
[Middlewares/Trailing-slash](https://github.com/middlewares/trailing-slash) to remove any trailing slashes in the url
[Monolog](https://github.com/Seldaek/monolog) for logging
[PHPMailer](https://github.com/PHPMailer/PHPMailer) for sending email
[Phinx](https://phinx.org/) for database migrations
[Odan/Session](https://github.com/odan/session) for managing the session(start session in middleware is not working)
[Odan/Session](https://github.com/odan/session) for managing the session
[Odan/Twig-Translation](https://github.com/odan/twig-translation) (partial usage) for compiling twig templates
[Selective/Config](https://github.com/selective-php/config) to manage config settings
[Slim/CSRF](https://github.com/slimphp/Slim-Csrf) to protect against csrf
Expand Down
8 changes: 3 additions & 5 deletions app/Middleware/SessionMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ class SessionMiddleware implements MiddlewareInterface
protected SessionInterface $session;

/**
* RedirectIfAuthenticated constructor.
* SessionMiddleware constructor.
*
* @param SessionInterface $session
*/
public function __construct(SessionInterface $session)
{
Expand All @@ -25,10 +27,6 @@ public function __construct(SessionInterface $session)
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$response = $handler->handle($request);
if (!$this->session->isStarted()) {
$this->session->start();
}

if (!$this->session->has('regen') || $this->session->get('regen') < time()) {
$this->session->regenerateId();
$this->session->set('regen', time() + 300);
Expand Down
1 change: 0 additions & 1 deletion bootstrap/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
} catch (NotFoundException $e) {
dd($e->getMessage());
}
$session->start();

try {
$i18n = $container->get(I18n::class);
Expand Down
2 changes: 1 addition & 1 deletion bootstrap/middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
$app->addMiddleware($container->get(WhoopsMiddleware::class));
$app->addMiddleware($container->get(CheckMailMiddleware::class));
$app->addMiddleware($container->get(SetLocaleMiddleware::class));
$app->addMiddleware($container->get(SessionMiddleware::class));
$app->addRoutingMiddleware();
$app->addMiddleware($container->get(TrailingSlash::class));
$app->addMiddleware($container->get(SessionMiddleware::class));
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "slim-auth",
"version": "0.3.2",
"version": "0.3.3",
"description": "",
"main": "index.js",
"directories": {
Expand Down

0 comments on commit df4ddef

Please sign in to comment.