Skip to content
Clone
d5939db
28 lines 1.2 KB Rust
use axum::extract::{Extension, State};
use crate::error::AuthError;
use crate::features::AuthService;
use crate::features::login::types::{LoginCmd, LoginResp};
use export::data::{AppRequest, AppRequestData, AppResponseData};
#[utoipa::path(
post,
path = "/auth/login",
tag = "auth",
request_body = AppRequestData<LoginCmd>,
responses(
(status = 200, description = "Authenticated. Returns access/refresh tokens and a public user view.", body = AppResponseData<LoginResp>),
(status = 400, description = "Validation / PoW failure.", body = super::openapi::ErrorBody),
(status = 401, description = "Invalid credentials.", body = super::openapi::ErrorBody),
(status = 403, description = "Account forbidden.", body = super::openapi::ErrorBody),
(status = 429, description = "Rate limited.", body = super::openapi::ErrorBody),
),
)]
pub(crate) async fn handler(
State(svc): State<AuthService>,
cid: Option<Extension<rate_limit::ClientId>>,
cmd: AppRequest<LoginCmd>,
) -> Result<AppResponseData<LoginResp>, AuthError> {
let resp = svc.login(cmd.into_inner(), cid.map(|c| c.0 .0)).await?;
Ok(AppResponseData::ok(resp))
}