Commit 580381d4 authored by Moreau Elise's avatar Moreau Elise
Browse files

add middleware to check if user is connected

parent f8540229
<?php
declare(strict_types=1);
namespace App\Application\Middleware;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\MiddlewareInterface as Middleware;
use Psr\Http\Server\RequestHandlerInterface as RequestHandler;
use Slim\Psr7\Response;
class RequireUserMiddleware implements Middleware
{
/**
* {@inheritdoc}
*/
public function process(Request $request, RequestHandler $handler): ResponseInterface
{
if (isset($request['user'])) {
return $handler->handle($request);
}
$response = new Response();
return $response->withHeader('Location', '/login')->withStatus(302);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment