Examples menu

๐Ÿ” Login Flow

PSR-15 middleware-based authentication. The login form is public; the dashboard and profile routes are protected by AuthMiddleware via Via::group()->middleware().

Three routes, one middleware. /examples/login is public. Dashboard and profile are protected via Via::group()->middleware(new AuthMiddleware(...)) โ€” one call shields both.
AuthMiddleware reads the session cookie from the PSR-7 request, looks up sessionData('auth') in the server-side session store, and either redirects (302) or passes the auth record downstream as a request attribute.
The handlers read $c->getRequestAttribute('auth') โ€” the middleware-set attribute is automatically bridged from the PSR-7 request to the Via Context. No manual session checks needed.
Logout clears the session and redirects back to the login form. The middleware will block any subsequent protected access until login succeeds again.

โšก Signals

username string TAB ""

Username input bound to the login form.

password string TAB ""

Password input. Cleared on failure.

error string TAB ""

Validation error message shown beneath the form.

๐ŸŽฏ Actions

login

Validates credentials. On success, writes auth to sessionData and redirects to the middleware-protected dashboard.

๐Ÿ‘ Views

login.html.twig

Login form. Redirects to dashboard if already authenticated.

login_dashboard.html.twig

Protected dashboard. Auth data injected by AuthMiddleware via request attributes.

login_profile.html.twig

Protected profile page. Same AuthMiddleware protects it via the shared group.

๐Ÿ›ก๏ธ Middleware

AuthMiddleware

PSR-15 middleware that checks sessionData('auth') and redirects unauthenticated requests to the login form. Implements SseAwareMiddleware to also protect SSE connections.