refactor(auth): refresh register handler
zhenyi committed
Modified lib/auth/handler/register.rs lib/auth/handler/register.rs +7 −7 View lib/auth/handler/register.rs
@@ -1,10 +1,10 @@
1use axum::Json;
21use axum::extract::{Extension, State};
32use axum_extra::extract::cookie::CookieJar;
43
54use crate::error::AuthError;
65use crate::features::AuthService;
76use crate::features::register::types::{RegisterCmd, RegisterResp};
7use export::data::{AppRequest, AppRequestData, AppResponseData};
88
99use super::cookies;
1010
@@ -12,9 +12,9 @@
1212 post,
1313 path = "/auth/register",
1414 tag = "auth",
15 request_body = RegisterCmd,
15 request_body = AppRequestData<RegisterCmd>,
1616 responses(
17 (status = 200, description = "Account created (possibly pending email verification).", body = RegisterResp),
17 (status = 200, description = "Account created (possibly pending email verification).", body = AppResponseData<RegisterResp>),
1818 (status = 400, description = "Validation / PoW failure.", body = super::openapi::ErrorBody),
1919 (status = 409, description = "Email or username already taken.", body = super::openapi::ErrorBody),
2020 (status = 429, description = "Rate limited.", body = super::openapi::ErrorBody),
@@ -24,10 +24,10 @@
2424 State(svc): State<AuthService>,
2525 jar: CookieJar,
2626 cid: Option<Extension<rate_limit::ClientId>>,
27 Json(cmd): Json<RegisterCmd>,
28) -> Result<(CookieJar, Json<RegisterResp>), AuthError> {
29 let resp = svc.register(cmd, cid.map(|c| c.0 .0)).await?;
27 cmd: AppRequest<RegisterCmd>,
28) -> Result<(CookieJar, AppResponseData<RegisterResp>), AuthError> {
29 let resp = svc.register(cmd.into_inner(), cid.map(|c| c.0 .0)).await?;
3030 let cookie = cookies::temp_key_to_cookie(&svc.config, &resp.temp_key);
3131 let jar = jar.add(cookie);
32 Ok((jar, Json(resp)))
32 Ok((jar, AppResponseData::ok(resp)))
3333}