mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-04-19 12:24:53 -04:00
refactor: remove server type
This commit is contained in:
parent
0906febe95
commit
2dc22004a1
4 changed files with 25 additions and 15 deletions
|
@ -192,11 +192,11 @@ impl UserCloudServiceProvider for ServerProvider {
|
|||
/// to create a new [AppFlowyServer] if it doesn't exist. Once the [AuthType] is set,
|
||||
/// it will be used when user open the app again.
|
||||
///
|
||||
fn set_auth_type(&self, auth_type: &AuthType) {
|
||||
fn set_server_auth_type(&self, auth_type: &AuthType) {
|
||||
self.set_auth_type(*auth_type);
|
||||
}
|
||||
|
||||
fn get_auth_type(&self) -> AuthType {
|
||||
fn get_server_auth_type(&self) -> AuthType {
|
||||
self.get_auth_type()
|
||||
}
|
||||
|
||||
|
|
|
@ -84,9 +84,9 @@ pub trait UserCloudServiceProvider: Send + Sync {
|
|||
/// * `enable_sync`: A boolean indicating whether synchronization should be enabled or disabled.
|
||||
fn set_enable_sync(&self, uid: i64, enable_sync: bool);
|
||||
|
||||
fn set_auth_type(&self, auth_type: &AuthType);
|
||||
fn set_server_auth_type(&self, auth_type: &AuthType);
|
||||
|
||||
fn get_auth_type(&self) -> AuthType;
|
||||
fn get_server_auth_type(&self) -> AuthType;
|
||||
|
||||
/// Sets the network reachability
|
||||
///
|
||||
|
|
|
@ -45,14 +45,16 @@ pub async fn sign_in_with_email_password_handler(
|
|||
let manager = upgrade_manager(manager)?;
|
||||
let params: SignInParams = data.into_inner().try_into()?;
|
||||
|
||||
let old_authenticator = manager.cloud_services.get_auth_type();
|
||||
let old_authenticator = manager.cloud_services.get_server_auth_type();
|
||||
match manager
|
||||
.sign_in_with_password(¶ms.email, ¶ms.password)
|
||||
.await
|
||||
{
|
||||
Ok(token) => data_result_ok(token.into()),
|
||||
Err(err) => {
|
||||
manager.cloud_services.set_auth_type(&old_authenticator);
|
||||
manager
|
||||
.cloud_services
|
||||
.set_server_auth_type(&old_authenticator);
|
||||
return Err(err);
|
||||
},
|
||||
}
|
||||
|
@ -76,11 +78,11 @@ pub async fn sign_up(
|
|||
let params: SignUpParams = data.into_inner().try_into()?;
|
||||
let auth_type = params.auth_type;
|
||||
|
||||
let prev_auth_type = manager.cloud_services.get_auth_type();
|
||||
let prev_auth_type = manager.cloud_services.get_server_auth_type();
|
||||
match manager.sign_up(auth_type, BoxAny::new(params)).await {
|
||||
Ok(profile) => data_result_ok(UserProfilePB::from(profile)),
|
||||
Err(err) => {
|
||||
manager.cloud_services.set_auth_type(&prev_auth_type);
|
||||
manager.cloud_services.set_server_auth_type(&prev_auth_type);
|
||||
Err(err)
|
||||
},
|
||||
}
|
||||
|
|
|
@ -351,7 +351,7 @@ impl UserManager {
|
|||
params: SignInParams,
|
||||
authenticator: AuthType,
|
||||
) -> Result<UserProfile, FlowyError> {
|
||||
self.cloud_services.set_auth_type(&authenticator);
|
||||
self.cloud_services.set_server_auth_type(&authenticator);
|
||||
|
||||
let response: AuthResponse = self
|
||||
.cloud_services
|
||||
|
@ -403,7 +403,7 @@ impl UserManager {
|
|||
) -> Result<UserProfile, FlowyError> {
|
||||
// sign out the current user if there is one
|
||||
let migration_user = self.get_migration_user(&auth_type).await;
|
||||
self.cloud_services.set_auth_type(&auth_type);
|
||||
self.cloud_services.set_server_auth_type(&auth_type);
|
||||
let auth_service = self.cloud_services.get_user_service()?;
|
||||
let response: AuthResponse = auth_service.sign_up(params).await?;
|
||||
let new_user_profile = UserProfile::from((&response, &auth_type));
|
||||
|
@ -712,7 +712,7 @@ impl UserManager {
|
|||
authenticator: &AuthType,
|
||||
email: &str,
|
||||
) -> Result<String, FlowyError> {
|
||||
self.cloud_services.set_auth_type(authenticator);
|
||||
self.cloud_services.set_server_auth_type(authenticator);
|
||||
|
||||
let auth_service = self.cloud_services.get_user_service()?;
|
||||
let url = auth_service.generate_sign_in_url_with_email(email).await?;
|
||||
|
@ -724,7 +724,9 @@ impl UserManager {
|
|||
email: &str,
|
||||
password: &str,
|
||||
) -> Result<GotrueTokenResponse, FlowyError> {
|
||||
self.cloud_services.set_auth_type(&AuthType::AppFlowyCloud);
|
||||
self
|
||||
.cloud_services
|
||||
.set_server_auth_type(&AuthType::AppFlowyCloud);
|
||||
let auth_service = self.cloud_services.get_user_service()?;
|
||||
let response = auth_service.sign_in_with_password(email, password).await?;
|
||||
Ok(response)
|
||||
|
@ -735,7 +737,9 @@ impl UserManager {
|
|||
email: &str,
|
||||
redirect_to: &str,
|
||||
) -> Result<(), FlowyError> {
|
||||
self.cloud_services.set_auth_type(&AuthType::AppFlowyCloud);
|
||||
self
|
||||
.cloud_services
|
||||
.set_server_auth_type(&AuthType::AppFlowyCloud);
|
||||
let auth_service = self.cloud_services.get_user_service()?;
|
||||
auth_service
|
||||
.sign_in_with_magic_link(email, redirect_to)
|
||||
|
@ -748,7 +752,9 @@ impl UserManager {
|
|||
email: &str,
|
||||
passcode: &str,
|
||||
) -> Result<GotrueTokenResponse, FlowyError> {
|
||||
self.cloud_services.set_auth_type(&AuthType::AppFlowyCloud);
|
||||
self
|
||||
.cloud_services
|
||||
.set_server_auth_type(&AuthType::AppFlowyCloud);
|
||||
let auth_service = self.cloud_services.get_user_service()?;
|
||||
let response = auth_service.sign_in_with_passcode(email, passcode).await?;
|
||||
Ok(response)
|
||||
|
@ -758,7 +764,9 @@ impl UserManager {
|
|||
&self,
|
||||
oauth_provider: &str,
|
||||
) -> Result<String, FlowyError> {
|
||||
self.cloud_services.set_auth_type(&AuthType::AppFlowyCloud);
|
||||
self
|
||||
.cloud_services
|
||||
.set_server_auth_type(&AuthType::AppFlowyCloud);
|
||||
let auth_service = self.cloud_services.get_user_service()?;
|
||||
let url = auth_service
|
||||
.generate_oauth_url_with_provider(oauth_provider)
|
||||
|
|
Loading…
Add table
Reference in a new issue