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

28 lines
1.0 KiB
Rust
Raw Normal View History

use crate::{entities::*, errors::UserError, services::user::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(name = "sign_in", skip(data, session), fields(email = %data.email), err)]
2021-09-04 08:53:58 +00:00
pub async fn sign_in(data: Data<SignInRequest>, session: Unit<Arc<UserSession>>) -> DataResult<UserProfile, UserError> {
let params: SignInParams = data.into_inner().try_into()?;
2021-09-04 08:53:58 +00:00
let user_profile = session.sign_in(params).await?;
data_result(user_profile)
2021-07-05 13:23:13 +00:00
}
#[tracing::instrument(
2021-07-25 00:13:59 +00:00
name = "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,
),
err
2021-07-05 13:23:13 +00:00
)]
2021-09-04 08:53:58 +00:00
pub async fn sign_up(data: Data<SignUpRequest>, session: Unit<Arc<UserSession>>) -> DataResult<UserProfile, UserError> {
let params: SignUpParams = data.into_inner().try_into()?;
2021-09-04 08:53:58 +00:00
let user_profile = session.sign_up(params).await?;
2021-09-04 08:53:58 +00:00
data_result(user_profile)
}