refactor(auth): refresh me handler
zhenyi committed
Modified lib/auth/handler/me.rs lib/auth/handler/me.rs +4 −4 View lib/auth/handler/me.rs
@@ -1,4 +1,3 @@
1use axum::Json;
21use axum::extract::State;
32use jwt::extractor::AuthUser;
43
@@ -8,13 +7,14 @@
87use crate::error::AuthError;
98use crate::features::AuthService;
109use crate::features::login::types::UserMe;
10use export::data::AppResponseData;
1111
1212#[utoipa::path(
1313 get,
1414 path = "/auth/me",
1515 tag = "auth",
1616 responses(
17 (status = 200, description = "Authenticated user profile (full view, including privileged fields).", body = UserMe),
17 (status = 200, description = "Authenticated user profile (full view, including privileged fields).", body = AppResponseData<UserMe>),
1818 (status = 401, description = "Missing or invalid access token.", body = super::openapi::ErrorBody),
1919 (status = 404, description = "User not found.", body = super::openapi::ErrorBody),
2020 ),
@@ -25,12 +25,12 @@
2525pub(crate) async fn handler(
2626 State(svc): State<AuthService>,
2727 AuthUser { claims }: AuthUser,
28) -> Result<Json<UserMe>, AuthError> {
28) -> Result<AppResponseData<UserMe>, AuthError> {
2929 let db = svc.db.writer();
3030 let model = user_entity::Entity::find_by_id(claims.sub)
3131 .one(&db)
3232 .await
3333 .map_err(AuthError::from)?
3434 .ok_or_else(|| AuthError::NotFound(format!("user {}", claims.sub)))?;
35 Ok(Json(UserMe::from(model)))
35 Ok(AppResponseData::ok(UserMe::from(model)))
3636}