AppFlowy/rust-lib/flowy-user/src/handlers/auth_handler.rs

40 lines
1.2 KiB
Rust
Raw Normal View History

use crate::{entities::*, errors::UserError, services::user_session::UserSession};
2021-07-08 13:23:44 +00:00
use flowy_dispatch::prelude::*;
2021-07-09 15:31:44 +00:00
use std::{convert::TryInto, sync::Arc};
// tracing instrument 👉🏻 https://docs.rs/tracing/0.1.26/tracing/attr.instrument.html
#[tracing::instrument(
2021-07-05 13:23:13 +00:00
name = "user_sign_in",
skip(data, session),
fields(
email = %data.email,
)
)]
pub async fn user_sign_in_handler(
data: Data<SignInRequest>,
2021-07-23 06:54:31 +00:00
session: Unit<Arc<UserSession>>,
) -> ResponseResult<UserDetail, UserError> {
let params: SignInParams = data.into_inner().try_into()?;
let user = session.sign_in(params).await?;
let user_detail = UserDetail::from(user);
response_ok(user_detail)
2021-07-05 13:23:13 +00:00
}
#[tracing::instrument(
name = "user_sign_up",
2021-07-09 15:31:44 +00:00
skip(data, session),
2021-07-05 13:23:13 +00:00
fields(
email = %data.email,
name = %data.name,
2021-07-05 13:23:13 +00:00
)
)]
pub async fn user_sign_up_handler(
2021-07-09 15:31:44 +00:00
data: Data<SignUpRequest>,
2021-07-23 06:54:31 +00:00
session: Unit<Arc<UserSession>>,
) -> ResponseResult<UserDetail, UserError> {
let params: SignUpParams = data.into_inner().try_into()?;
let user = session.sign_up(params).await?;
let user_detail = UserDetail::from(user);
response_ok(user_detail)
}