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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
//! # Torii Axum Integration
//!
//! This crate provides Axum routes and middleware for the Torii authentication framework.
//! It offers a simple way to add authentication to your Axum application with support for
//! multiple authentication methods.
//!
//! ## Features
//!
//! - **Core Authentication**: Session management, user info, health checks
//! - **Password Authentication** (feature = "password"): Registration, login, password changes
//! - **Magic Link Authentication** (feature = "magic-link"): Passwordless email authentication
//! - **OAuth** (feature = "oauth"): Coming soon
//! - **Passkey** (feature = "passkey"): Coming soon
//!
//! ## Example Usage
//!
//! ```rust,no_run
//! use std::sync::Arc;
//! use axum::{Router, routing::get};
//! use torii::{Torii, SeaORMRepositoryProvider};
//! use torii_axum::{routes, HasTorii, auth_middleware, CookieConfig};
//!
//! // Define your application state with a torii field
//! #[derive(Clone)]
//! struct AppState {
//! torii: Arc<Torii<SeaORMRepositoryProvider>>,
//! // Add other state fields as needed
//! // database: Arc<sqlx::PgPool>,
//! }
//!
//! // Implement HasTorii for your state
//! impl HasTorii<SeaORMRepositoryProvider> for AppState {
//! fn torii(&self) -> &Arc<Torii<SeaORMRepositoryProvider>> {
//! &self.torii
//! }
//! }
//!
//! #[tokio::main]
//! async fn main() {
//! // Set up Torii with your storage backend
//! let repositories = Arc::new(SeaORMRepositoryProvider::new(pool));
//! let torii = Arc::new(Torii::new(repositories));
//!
//! // Create your application state
//! let state = AppState { torii: torii.clone() };
//!
//! // Create auth routes with custom cookie configuration
//! let auth_routes = routes(torii)
//! .with_cookie_config(CookieConfig::development())
//! .build();
//!
//! // Create your application router
//! let app = Router::new()
//! .nest("/auth", auth_routes)
//! .route("/protected", get(protected_handler))
//! .with_state(state.clone())
//! .layer(axum::middleware::from_fn_with_state(
//! state,
//! auth_middleware::<AppState, SeaORMRepositoryProvider>
//! ));
//!
//! // Run your server
//! let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
//! axum::serve(listener, app).await.unwrap();
//! }
//!
//! async fn protected_handler() -> &'static str {
//! "This route requires authentication!"
//! }
//! ```
pub use ;
pub use ;
pub use ;
pub use create_router;
pub use ;
use Router;
use Arc;
use Torii;
use RepositoryProvider;
/// Create authentication routes for your Axum application.
///
/// This function creates a router with all available authentication endpoints
/// based on the features enabled in your Cargo.toml.
///
/// # Arguments
///
/// * `torii` - An Arc-wrapped Torii instance configured with your storage backend
///
/// # Returns
///
/// A Router that can be nested into your application at any path (e.g., "/auth")
///
/// # Example
///
/// ```rust,no_run
/// let auth_routes = torii_axum::routes(torii);
/// let app = Router::new().nest("/auth", auth_routes);
/// ```
/// Builder for configuring authentication routes