1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//! Middleware — request gates of two flavors.
//!
//! Dioxus and Next.js both use the word "middleware" but for different things.
//! Both apply, both live here:
//!
//! ## 1. Route matchers (Next.js-style; client-side gates)
//!
//! Functions like `is_public` and `is_authenticated` are called by the root
//! `App` component (in `src/app/layout.rs`) every render, BEFORE the matched
//! page resolves. Used to redirect unauthenticated users, enforce subscription
//! tiers, etc.
//!
//! ```rust,ignore
//! #[component]
//! pub fn App() -> Element {
//! let route = use_route::<Route>();
//!
//! if !middleware::is_public(&route) {
//! let user = use_auth();
//! if user.is_none() {
//! return rsx! { Redirect { to: Route::SignIn } };
//! }
//! }
//!
//! rsx! { document::Stylesheet { ... } Outlet::<Route> {} }
//! }
//! ```
//!
//! ## 2. Tower middleware (Dioxus-style; server-side HTTP gates)
//!
//! Functions decorated for use as `axum::middleware::from_fn(...)` layers
//! applied in `main.rs`'s `dioxus::serve()` closure. Standard Tower
//! middleware — runs on every HTTP request, server-side only.
//!
//! Per-server-fn Tower layers (e.g. `TimeoutLayer` on a single endpoint)
//! use the `#[middleware(...)]` attribute on the server fn directly,
//! NOT this file. This file is for layers applied globally.
use crateRoute;
// ============================================================================
// Route matchers (client-side gates)
// ============================================================================
/// Routes anyone can access without authentication.
///
/// Add public-facing pages here (landing, pricing, terms, sign-in, etc.).
/// Routes that require an authenticated user.
///
/// Sign-in flow should send users back to the original URL after auth.
// ============================================================================
// Tower middleware (server-side gates)
// ============================================================================
/// Log every HTTP request the server receives (method + path + status).
///
/// Wired up in `main.rs` via:
///
/// ```rust,ignore
/// .layer(axum::middleware::from_fn(crate::middleware::log_request))
/// ```
pub async