File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed
Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change 2525const AIO_SESSION_MAX_LIFETIME = '86400 ' ; // (24h)
2626const AIO_COOKIE_LIFETIME = '0 ' ; // Auto logout on browser close
2727const AIO_LOG_ERRORS_MAX_LEN = '0 ' ; // Log whole log messages
28-
2928const AIO_TWIG_CACHE_PATH = false ; // e.g., __DIR__ . '/../var/twig-cache'
3029const AIO_DISPLAY_ERRORS = false ;
3130
5453$ app = AppFactory::create ();
5554$ responseFactory = $ app ->getResponseFactory ();
5655
56+ // Register CSRF middleware (container-only)
5757$ container ->set (Guard::class, function () use ($ responseFactory ): Guard {
5858 $ guard = new Guard ($ responseFactory );
5959 $ guard ->setPersistentTokenMode (true );
6060 return $ guard ;
6161});
6262
6363session_start ();
64+
65+ // Activate CSRF middleware for all routes
6466$ app ->add (Guard::class);
6567
68+ // Setup and activate Twig middleware
6669$ twig = Twig::create (__DIR__ . '/../templates/ ' ,
6770 [ 'cache ' => AIO_TWIG_CACHE_PATH ]
6871);
6972$ app ->add (TwigMiddleware::create ($ app , $ twig ));
7073
74+ // Add CSRF extension to Twig so templates can access CSRF tokens
7175$ twig ->addExtension (new \AIO \Twig \CsrfExtension ($ container ->get (Guard::class)));
7276
77+ // Establish and activate authentication middleware for all routes
7378$ app ->add (new \AIO \Middleware \AuthMiddleware ($ container ->get (\AIO \Auth \AuthManager::class)));
7479
7580//-------------------------------------------------
You can’t perform that action at this time.
0 commit comments