d5939db
use axum::Router;
use axum::middleware::from_fn_with_state;
use axum::routing::{get, post};
use crate::features::AuthService;
use jwt::inject_jwt_ctx;
use rate_limit::ratelimit;
pub fn router(svc: AuthService) -> Router {
let auth = Router::new()
.route("/register", post(crate::handler::register::handler))
.route("/login", post(crate::handler::login::handler))
.route("/logout", post(crate::handler::logout::handler))
.route("/refresh", post(crate::handler::refresh::handler))
.route(
"/pow/challenge",
get(crate::handler::pow::handler),
)
.route(
"/email/verify",
post(crate::handler::email::verify::handler),
)
.route(
"/email/resend",
post(crate::handler::email::resend::handler),
)
.route(
"/email/reclaim",
post(crate::handler::email::reclaim::handler),
)
.route(
"/password/forgot",
post(crate::handler::password::forgot::handler),
)
.route(
"/password/reset",
post(crate::handler::password::reset::handler),
)
.route("/agreements", get(crate::handler::agreement::list::handler))
.route(
"/agreements/accept",
post(crate::handler::agreement::accept::handler),
)
.route(
"/oauth/providers",
get(crate::handler::oauth::providers::handler),
)
.route(
"/oauth/authorize",
post(crate::handler::oauth::authorize::handler),
)
.route(
"/oauth/callback",
get(crate::handler::oauth::callback::handler),
)
.route(
"/me",
get(crate::handler::me::handler)
.layer(from_fn_with_state(svc.clone(), inject_jwt_ctx::<AuthService>)),
)
.layer(from_fn_with_state(svc.clone(), ratelimit::<AuthService>))
.with_state(svc);
Router::new().nest("/auth", auth)
}