You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/start/framework/react/guide/middleware.md
+79Lines changed: 79 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -758,3 +758,82 @@ Middleware functionality is tree-shaken based on the environment for each bundle
758
758
759
759
- On the server, nothing is tree-shaken, so all code used in middleware will be included in the server bundle.
760
760
- On the client, all server-specific code is removed from the client bundle. This means any code used in the `server` method is always removed from the client bundle. `data` validation code will also be removed.
761
+
762
+
## Middleware Factories
763
+
764
+
Static middlewares are created once and reused across routes. A middleware factory wraps that creation in a function, allowing it to accept parameters and behave differently depending on the caller's needs. Authorization is a common use case.
765
+
766
+
**Authentication (Static Base Middleware) Example:**
767
+
768
+
This middleware validates the session and injects it into `context` for downstream middlewares.
The middleware validates access based on the dynamic `permissions` parameter, composing with `authMiddleware` so `context.session` is already available.
0 commit comments