Skip to content
Clone

refactor(auth): refresh email verify handler

zhenyi committed
parent a5bdaf7 commit b8e222a Browse files

1 file changed

+9 −8

Modified lib/auth/handler/email/verify.rs View lib/auth/handler/email/verify.rs
@@ -1,9 +1,9 @@
1use axum::Json;
21use axum::extract::State;
32use axum_extra::extract::cookie::CookieJar;
43
54use crate::error::AuthError;
65use crate::features::AuthService;
6use export::data::{AppRequest, AppRequestData, AppResponseData};
77
88use super::super::cookies;
99
@@ -11,9 +11,9 @@
1111 post,
1212 path = "/auth/email/verify",
1313 tag = "auth",
14 request_body = crate::features::email_code::types::VerifyCodeCmd,
14 request_body = AppRequestData<crate::features::email_code::types::VerifyCodeCmd>,
1515 responses(
16 (status = 200, description = "Code verified; the verification-code row id is returned.", body = crate::features::email_code::types::VerifyCodeResult),
16 (status = 200, description = "Code verified; the verification-code row id is returned.", body = AppResponseData<crate::features::email_code::types::VerifyCodeResult>),
1717 (status = 400, description = "Invalid code, missing temp_key cookie, or expired.", body = super::super::openapi::ErrorBody),
1818 (status = 401, description = "Unauthorized.", body = super::super::openapi::ErrorBody),
1919 (status = 429, description = "Rate limited.", body = super::super::openapi::ErrorBody),
@@ -22,19 +22,20 @@
2222pub(crate) async fn handler(
2323 State(svc): State<AuthService>,
2424 jar: CookieJar,
25 Json(cmd): Json<crate::features::email_code::types::VerifyCodeCmd>,
25 cmd: AppRequest<crate::features::email_code::types::VerifyCodeCmd>,
2626) -> Result<
2727 (
2828 CookieJar,
29 Json<crate::features::email_code::types::VerifyCodeResult>,
29 AppResponseData<crate::features::email_code::types::VerifyCodeResult>,
3030 ),
3131 AuthError,
3232> {
33 let cmd = cmd.into_inner();
3334 let purpose = cmd.purpose;
34 let email = cmd.email.clone();
35 let email = cmd.email;
3536 let user_id = cmd.user_id;
3637 let code = cmd.code;
37 let temp_key_value = cmd.temp_key_value.clone();
38 let temp_key_value = cmd.temp_key_value;
3839
3940 let cookie_name = crate::features::email_code::usecase::cookie_name(
4041 &svc.config.cookie_name_prefix,
@@ -47,5 +48,5 @@
4748 .await?;
4849
4950 let jar = cookies::remove_cookie(jar, &cookie_name);
50 Ok((jar, Json(result)))
51 Ok((jar, AppResponseData::ok(result)))
5152}