Skip to content
Clone

refactor(auth): refresh password reset handler

zhenyi committed
parent 202ece5 commit a5741bc Browse files

1 file changed

+8 −8

Modified lib/auth/handler/password/reset.rs View lib/auth/handler/password/reset.rs
@@ -1,10 +1,10 @@
1use axum::Json;
21use axum::extract::State;
32use axum_extra::extract::cookie::CookieJar;
43
54use crate::error::AuthError;
65use crate::features::AuthService;
7use crate::features::reset_password::types::{ResetPasswordCmd, ResetPasswordResp};
6use export::auth::reset_password::{ResetPasswordCmd, ResetPasswordResp};
7use export::data::{AppRequest, AppRequestData, AppResponseData};
88
99use super::super::cookies;
1010
@@ -12,9 +12,9 @@
1212 post,
1313 path = "/auth/password/reset",
1414 tag = "auth",
15 request_body = ResetPasswordCmd,
15 request_body = AppRequestData<ResetPasswordCmd>,
1616 responses(
17 (status = 200, description = "Password updated; all sessions revoked.", body = ResetPasswordResp),
17 (status = 200, description = "Password updated; all sessions revoked.", body = AppResponseData<ResetPasswordResp>),
1818 (status = 400, description = "Missing temp_key cookie, weak password, or invalid token.", body = super::super::openapi::ErrorBody),
1919 (status = 401, description = "Unauthorized.", body = super::super::openapi::ErrorBody),
2020 ),
@@ -22,8 +22,8 @@
2222pub(crate) async fn handler(
2323 State(svc): State<AuthService>,
2424 jar: CookieJar,
25 Json(mut cmd): Json<ResetPasswordCmd>,
26) -> Result<(CookieJar, Json<ResetPasswordResp>), AuthError> {
25 mut cmd: AppRequest<ResetPasswordCmd>,
26) -> Result<(CookieJar, AppResponseData<ResetPasswordResp>), AuthError> {
2727 let cookie_name = crate::features::forgot_password::usecase::cookie_name(
2828 &svc.config.cookie_name_prefix,
2929 &cmd.email,
@@ -33,7 +33,7 @@
3333 .ok_or_else(|| AuthError::BadRequest(format!("missing temp_key cookie {cookie_name}")))?;
3434 cmd.temp_key_value = value;
3535
36 let resp = svc.reset_password(cmd).await?;
36 let resp = svc.reset_password(cmd.into_inner()).await?;
3737 let jar = cookies::remove_cookie(jar, &cookie_name);
38 Ok((jar, Json(resp)))
38 Ok((jar, AppResponseData::ok(resp)))
3939}