use crate::Client;
use crate::errors::{Error, Result};
use crate::raw::{base, functions};
use crate::types::User;
impl Client {
pub async fn sign_in(&self, phone_number: &str, phone_code_hash: &str, phone_code: &str) -> Result<User> {
let auth = self.sign_in_raw(phone_number, phone_code_hash, phone_code).await?;
self.authorized(auth).await
}
pub(crate) async fn sign_in_raw(
&self,
phone_number: &str,
phone_code_hash: &str,
phone_code: &str,
) -> Result<base::auth::Authorization> {
let request = functions::auth::SignIn {
phone_number: phone_number.into(),
phone_code_hash: phone_code_hash.into(),
phone_code: Some(phone_code.into()),
email_verification: None,
};
self.invoke(&request).await
}
pub(crate) async fn authorized(&self, auth: base::auth::Authorization) -> Result<User> {
Ok(User::from_raw(self, self.authorized_raw(auth).await?))
}
pub(crate) async fn authorized_raw(&self, auth: base::auth::Authorization) -> Result<base::User> {
match auth {
base::auth::Authorization::Authorization(a) => {
self.set_me(&a.user);
self.save().await?;
Ok(a.user)
}
base::auth::Authorization::AuthorizationSignUpRequired(_) => Err(Error::SignUpRequired),
}
}
}