1212
1313namespace Koded \Session ;
1414
15- use Koded \Http \{StatusCode , ServerResponse };
15+ use Koded \Http \{ServerResponse , StatusCode };
1616use Koded \Stdlib \Interfaces \ConfigurationFactory ;
1717use Psr \Http \Message \{ResponseInterface , ServerRequestInterface };
1818use Psr \Http \Server \{MiddlewareInterface , RequestHandlerInterface };
2121class SessionAuthenticatedMiddleware implements MiddlewareInterface
2222{
2323 public const AUTHENTICATED = 'authenticated ' ;
24- public const LOGIN_URI = 'loginUri ' ;
24+ public const LOGIN_URI = 'loginUri ' ;
2525
2626 private $ redirectTo = '/ ' ;
2727
@@ -32,17 +32,12 @@ public function __construct(ConfigurationFactory $settings)
3232
3333 public function process (ServerRequestInterface $ request , RequestHandlerInterface $ handler ): ResponseInterface
3434 {
35- if (true ! == ($ _SESSION [self ::AUTHENTICATED ] ?? false )) {
36- return $ this -> redirect ( );
35+ if (true = == ($ _SESSION [self ::AUTHENTICATED ] ?? false )) {
36+ return $ handler -> handle ( $ request );
3737 }
3838
39- return $ handler ->handle ($ request );
40- }
41-
42- private function redirect (): ResponseInterface
43- {
4439 // Ajax requests should be handled in the browser
45- if (strtoupper ($ _SERVER ['HTTP_X_REQUESTED_WITH ' ] ?? '' ) === ' XMLHTTPREQUEST ' ) {
40+ if (' XMLHTTPREQUEST ' === strtoupper ($ _SERVER ['HTTP_X_REQUESTED_WITH ' ] ?? '' )) {
4641 return (new ServerResponse (json_encode ([
4742 'location ' => $ this ->redirectTo ,
4843 'status ' => StatusCode::UNAUTHORIZED
0 commit comments