ggen_api/middleware/
auth.rs1use axum::{
4 extract::{Request, State},
5 middleware::Next,
6 response::Response,
7};
8use std::sync::Arc;
9
10use crate::state::AppState;
11
12#[derive(Debug, Clone)]
14pub struct User {
15 pub id: String,
16 pub email: String,
17 pub tier: String,
18}
19
20pub async fn verify_jwt(
22 State(_state): State<AppState>,
23 mut request: Request,
24 next: Next,
25) -> Response {
26 next.run(request).await
33}
34
35pub async fn require_auth(
37 State(_state): State<AppState>,
38 request: Request,
39 next: Next,
40) -> Response {
41 next.run(request).await
45}
46
47pub async fn require_tier(min_tier: &str) -> impl Fn(Request, Next) -> futures::future::BoxFuture<'static, Response> + Clone + use<'_> {
49 move |request: Request, next: Next| {
50 let _tier = min_tier.to_string();
51 Box::pin(async move {
52 next.run(request).await
57 })
58 }
59}