Skip to content
Clone

refactor(auth): refresh login handler

zhenyi committed
parent b8e222a commit 50ae2ff Browse files

1 file changed

+7 −7

Modified lib/auth/handler/login.rs View lib/auth/handler/login.rs
@@ -1,17 +1,17 @@
1use axum::Json;
21use axum::extract::{Extension, State};
32
43use crate::error::AuthError;
54use crate::features::AuthService;
65use crate::features::login::types::{LoginCmd, LoginResp};
6use export::data::{AppRequest, AppRequestData, AppResponseData};
77
88#[utoipa::path(
99 post,
1010 path = "/auth/login",
1111 tag = "auth",
12 request_body = LoginCmd,
12 request_body = AppRequestData<LoginCmd>,
1313 responses(
14 (status = 200, description = "Authenticated. Returns access/refresh tokens and a public user view.", body = LoginResp),
14 (status = 200, description = "Authenticated. Returns access/refresh tokens and a public user view.", body = AppResponseData<LoginResp>),
1515 (status = 400, description = "Validation / PoW failure.", body = super::openapi::ErrorBody),
1616 (status = 401, description = "Invalid credentials.", body = super::openapi::ErrorBody),
1717 (status = 403, description = "Account forbidden.", body = super::openapi::ErrorBody),
@@ -21,8 +21,8 @@
2121pub(crate) async fn handler(
2222 State(svc): State<AuthService>,
2323 cid: Option<Extension<rate_limit::ClientId>>,
24 Json(cmd): Json<LoginCmd>,
25) -> Result<Json<LoginResp>, AuthError> {
26 let resp = svc.login(cmd, cid.map(|c| c.0 .0)).await?;
27 Ok(Json(resp))
24 cmd: AppRequest<LoginCmd>,
25) -> Result<AppResponseData<LoginResp>, AuthError> {
26 let resp = svc.login(cmd.into_inner(), cid.map(|c| c.0 .0)).await?;
27 Ok(AppResponseData::ok(resp))
2828}