Skip to content
Clone

refactor(auth): refresh logout handler

zhenyi committed
parent 50ae2ff commit af5b4db Browse files

1 file changed

+8 −8

Modified lib/auth/handler/logout.rs View lib/auth/handler/logout.rs
@@ -1,26 +1,26 @@
1use axum::Json;
21use axum::extract::State;
32use axum::http::HeaderMap;
43
54use crate::error::AuthError;
65use crate::features::AuthService;
7use crate::features::logout::types::{LogoutCmd, LogoutResp};
6use export::auth::logout::{LogoutCmd, LogoutResp};
7use export::data::{AppRequest, AppRequestData, AppResponseData};
88
99#[utoipa::path(
1010 post,
1111 path = "/auth/logout",
1212 tag = "auth",
13 request_body = LogoutCmd,
13 request_body = AppRequestData<LogoutCmd>,
1414 responses(
15 (status = 200, description = "Refresh token revoked.", body = LogoutResp),
15 (status = 200, description = "Refresh token revoked.", body = AppResponseData<LogoutResp>),
1616 (status = 401, description = "Invalid or expired refresh token.", body = super::openapi::ErrorBody),
1717 ),
1818)]
1919pub(crate) async fn handler(
2020 State(svc): State<AuthService>,
2121 headers: HeaderMap,
22 Json(cmd): Json<LogoutCmd>,
23) -> Result<Json<LogoutResp>, AuthError> {
22 cmd: AppRequest<LogoutCmd>,
23) -> Result<AppResponseData<LogoutResp>, AuthError> {
2424 let access_token = headers
2525 .get(axum::http::header::AUTHORIZATION)
2626 .and_then(|v| v.to_str().ok())
@@ -29,6 +29,6 @@
2929 .or_else(|| v.strip_prefix("bearer "))
3030 })
3131 .map(|s| s.to_string());
32 let resp = svc.logout(cmd, access_token).await?;
33 Ok(Json(resp))
32 let resp = svc.logout(cmd.into_inner(), access_token).await?;
33 Ok(AppResponseData::ok(resp))
3434}