Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

fix: set auth type

Nathan2c5f41b58062
diff --git a/frontend/appflowy_flutter/lib/workspace/application/settings/settings_dialog_bloc.dart b/frontend/appflowy_flutter/lib/workspace/application/settings/settings_dialog_bloc.dart
index ce659d5262..726e95bb9e 100644
--- a/frontend/appflowy_flutter/lib/workspace/application/settings/settings_dialog_bloc.dart
+++ b/frontend/appflowy_flutter/lib/workspace/application/settings/settings_dialog_bloc.dart
@@ -2,6 +2,7 @@ import 'package:appflowy/user/application/user_listener.dart';
import 'package:appflowy_backend/dispatch/dispatch.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
+import 'package:appflowy_backend/protobuf/flowy-user/user_profile.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-user/workspace.pb.dart';
import 'package:appflowy_result/appflowy_result.dart';
import 'package:flutter/foundation.dart';
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/workspace/_sidebar_workspace_menu.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/workspace/_sidebar_workspace_menu.dart
index c9f464d43a..097da2c2ae 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/workspace/_sidebar_workspace_menu.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/workspace/_sidebar_workspace_menu.dart
@@ -389,7 +389,7 @@ class _CreateWorkspaceButton extends StatelessWidget {
workspaceBloc.add(
UserWorkspaceEvent.createWorkspace(
name,
- AuthTypePB.Local,
+ AuthTypePB.Server,
),
);
},
diff --git a/frontend/rust-lib/event-integration-test/tests/user/af_cloud_test/anon_user_test.rs b/frontend/rust-lib/event-integration-test/tests/user/af_cloud_test/anon_user_test.rs
index 1abdde509f..7f743b931c 100644
--- a/frontend/rust-lib/event-integration-test/tests/user/af_cloud_test/anon_user_test.rs
+++ b/frontend/rust-lib/event-integration-test/tests/user/af_cloud_test/anon_user_test.rs
@@ -72,7 +72,7 @@ async fn migrate_anon_user_data_to_af_cloud_test() {
let user = test.af_cloud_sign_up().await;
let workspace = test.get_current_workspace().await;
println!("user workspace: {:?}", workspace.id);
- assert_eq!(user.auth_type, AuthTypePB::AppFlowyCloud);
+ assert_eq!(user.auth_type, AuthTypePB::Server);
let user_first_level_views = test.get_all_workspace_views().await;
assert_eq!(user_first_level_views.len(), 3);
diff --git a/frontend/rust-lib/flowy-core/src/server_layer.rs b/frontend/rust-lib/flowy-core/src/server_layer.rs
index 4b1834c41c..b666ab4749 100644
--- a/frontend/rust-lib/flowy-core/src/server_layer.rs
+++ b/frontend/rust-lib/flowy-core/src/server_layer.rs
@@ -82,12 +82,12 @@ impl ServerProvider {
pub fn set_auth_type(&self, new_auth_type: AuthType) {
let old_type = self.get_auth_type();
- info!(
- "ServerProvider: set auth type from {:?} to {:?}",
- old_type, new_auth_type
- );
-
if old_type != new_auth_type {
+ info!(
+ "ServerProvider: auth type from {:?} to {:?}",
+ old_type, new_auth_type
+ );
+
self.auth_type.store(Arc::new(new_auth_type));
if let Some((auth_type, _)) = self.providers.remove(&old_type) {
info!("ServerProvider: remove old auth type: {:?}", auth_type);
diff --git a/frontend/rust-lib/flowy-core/src/user_state_callback.rs b/frontend/rust-lib/flowy-core/src/user_state_callback.rs
index e85b773ec4..f3eaa00543 100644
--- a/frontend/rust-lib/flowy-core/src/user_state_callback.rs
+++ b/frontend/rust-lib/flowy-core/src/user_state_callback.rs
@@ -55,7 +55,6 @@ impl UserStatusCallback for UserStatusCallbackImpl {
auth_type: &AuthType,
) -> FlowyResult<()> {
let workspace_id = user_workspace.workspace_id()?;
- self.server_provider.set_auth_type(*auth_type);
if let Some(cloud_config) = cloud_config {
self
@@ -102,8 +101,6 @@ impl UserStatusCallback for UserStatusCallbackImpl {
user_workspace,
device_id
);
- self.server_provider.set_auth_type(*auth_type);
-
self
.folder_manager
.initialize_after_sign_in(user_id)
@@ -130,8 +127,6 @@ impl UserStatusCallback for UserStatusCallbackImpl {
device_id: &str,
auth_type: &AuthType,
) -> FlowyResult<()> {
- self.server_provider.set_auth_type(*auth_type);
-
event!(
tracing::Level::TRACE,
"Notify did sign up: is new: {} user_workspace: {:?}, device_id: {}",
@@ -212,7 +207,6 @@ impl UserStatusCallback for UserStatusCallbackImpl {
user_workspace: &UserWorkspace,
auth_type: &AuthType,
) -> FlowyResult<()> {
- self.server_provider.set_auth_type(*auth_type);
self
.folder_manager
.initialize_after_open_workspace(user_id)
diff --git a/frontend/rust-lib/flowy-server/src/local_server/impls/folder.rs b/frontend/rust-lib/flowy-server/src/local_server/impls/folder.rs
index 31a65e7fa9..72bab514ec 100644
--- a/frontend/rust-lib/flowy-server/src/local_server/impls/folder.rs
+++ b/frontend/rust-lib/flowy-server/src/local_server/impls/folder.rs
@@ -84,7 +84,7 @@ impl FolderCloudService for LocalServerFolderCloudServiceImpl {
workspace_id: &Uuid,
view_ids: Vec<Uuid>,
) -> Result<(), FlowyError> {
- Err(FlowyError::local_version_not_support())
+ Ok(())
}
async fn get_publish_info(&self, view_id: &Uuid) -> Result<PublishInfo, FlowyError> {
diff --git a/frontend/rust-lib/flowy-server/src/local_server/impls/user.rs b/frontend/rust-lib/flowy-server/src/local_server/impls/user.rs
index 14d39690f9..e73943bbbe 100644
--- a/frontend/rust-lib/flowy-server/src/local_server/impls/user.rs
+++ b/frontend/rust-lib/flowy-server/src/local_server/impls/user.rs
@@ -48,7 +48,8 @@ impl UserCloudService for LocalServerUserServiceImpl {
latest_workspace: user_workspace.clone(),
user_workspaces: vec![user_workspace],
is_new_user: true,
- email: Some(params.email),
+ // Anon user doesn't have email
+ email: None,
token: None,
encryption_type: EncryptionType::NoEncryption,
updated_at: timestamp(),
diff --git a/frontend/rust-lib/flowy-user-pub/src/sql/workspace_sql.rs b/frontend/rust-lib/flowy-user-pub/src/sql/workspace_sql.rs
index 0570020716..cb6d299039 100644
--- a/frontend/rust-lib/flowy-user-pub/src/sql/workspace_sql.rs
+++ b/frontend/rust-lib/flowy-user-pub/src/sql/workspace_sql.rs
@@ -172,7 +172,6 @@ pub fn delete_all_then_insert_user_workspaces(
) -> FlowyResult<()> {
conn.immediate_transaction(|conn| {
delete_user_all_workspace(uid, auth_type, conn)?;
-
info!(
"Insert {} workspaces for user {} and auth type {:?}",
user_workspaces.len(),
diff --git a/frontend/rust-lib/flowy-user/src/entities/workspace.rs b/frontend/rust-lib/flowy-user/src/entities/workspace.rs
index ed8eb8aa76..99544eede4 100644
--- a/frontend/rust-lib/flowy-user/src/entities/workspace.rs
+++ b/frontend/rust-lib/flowy-user/src/entities/workspace.rs
@@ -255,9 +255,6 @@ impl From<i32> for AuthTypePB {
match value {
0 => AuthTypePB::Local,
1 => AuthTypePB::Server,
- // For historical reasons, 2 also maps to Server.
- // Check the AuthenticatorType in flowy-server-pub
- 2 => AuthTypePB::Server,
_ => AuthTypePB::Server,
}
}
diff --git a/frontend/rust-lib/flowy-user/src/event_handler.rs b/frontend/rust-lib/flowy-user/src/event_handler.rs
index bb38a9e0a0..905eb595f1 100644
--- a/frontend/rust-lib/flowy-user/src/event_handler.rs
+++ b/frontend/rust-lib/flowy-user/src/event_handler.rs
@@ -44,18 +44,12 @@ 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_service.get_server_auth_type();
match manager
.sign_in_with_password(&params.email, &params.password)
.await
{
Ok(token) => data_result_ok(token.into()),
- Err(err) => {
- manager
- .cloud_service
- .set_server_auth_type(&old_authenticator);
- return Err(err);
- },
+ Err(err) => Err(err),
}
}
@@ -77,13 +71,9 @@ 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_service.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_service.set_server_auth_type(&prev_auth_type);
- Err(err)
- },
+ Err(err) => Err(err),
}
}
diff --git a/frontend/rust-lib/flowy-user/src/user_manager/manager.rs b/frontend/rust-lib/flowy-user/src/user_manager/manager.rs
index 6cfa8bf16f..9520489771 100644
--- a/frontend/rust-lib/flowy-user/src/user_manager/manager.rs
+++ b/frontend/rust-lib/flowy-user/src/user_manager/manager.rs
@@ -132,18 +132,19 @@ impl UserManager {
if let Ok(session) = self.get_session() {
let user = self.get_user_profile_from_disk(session.user_id).await?;
+ self.cloud_service.set_server_auth_type(&user.auth_type);
// Get the current authenticator from the environment variable
- let current_authenticator = current_authenticator();
+ let env_auth_type = current_authenticator();
// If the current authenticator is different from the authenticator in the session and it's
// not a local authenticator, we need to sign out the user.
- if user.auth_type != AuthType::Local && user.auth_type != current_authenticator {
+ if user.auth_type != AuthType::Local && user.auth_type != env_auth_type {
event!(
tracing::Level::INFO,
- "Authenticator changed from {:?} to {:?}",
+ "Auth type changed from {:?} to {:?}",
user.auth_type,
- current_authenticator
+ env_auth_type
);
self.sign_out().await?;
return Ok(());
@@ -151,7 +152,7 @@ impl UserManager {
event!(
tracing::Level::INFO,
- "init user session: {}:{}, authenticator: {:?}",
+ "init user session: {}:{}, auth type: {:?}",
user.uid,
user.email,
user.auth_type,
@@ -389,9 +390,10 @@ impl UserManager {
auth_type: AuthType,
params: BoxAny,
) -> Result<UserProfile, FlowyError> {
+ self.cloud_service.set_server_auth_type(&auth_type);
+
// sign out the current user if there is one
let migration_user = self.get_migration_user(&auth_type).await;
- self.cloud_service.set_server_auth_type(&auth_type);
let auth_service = self.cloud_service.get_user_service()?;
let response: AuthResponse = auth_service.sign_up(params).await?;
let new_user_profile = UserProfile::from((&response, &auth_type));
@@ -401,28 +403,6 @@ impl UserManager {
Ok(new_user_profile)
}
- #[tracing::instrument(level = "info", skip(self))]
- pub async fn resume_sign_up(&self) -> Result<(), FlowyError> {
- let UserAuthProcess {
- user_profile,
- migration_user,
- response,
- authenticator,
- } = self
- .auth_process
- .lock()
- .await
- .clone()
- .ok_or(FlowyError::new(
- ErrorCode::Internal,
- "No resumable sign up data",
- ))?;
- self
- .continue_sign_up(&user_profile, migration_user, response, &authenticator)
- .await?;
- Ok(())
- }
-
#[tracing::instrument(level = "info", skip_all, err)]
async fn continue_sign_up(
&self,
@@ -436,9 +416,7 @@ impl UserManager {
self
.save_auth_data(&response, *auth_type, &new_session)
.await?;
- let _ = self
- .initial_user_awareness(&new_session, &new_user_profile.auth_type)
- .await;
+ let _ = self.initial_user_awareness(&new_session, auth_type).await;
self
.user_status_callback
.read()
@@ -670,6 +648,7 @@ impl UserManager {
}
}
+ #[instrument(level = "info", skip_all)]
pub(crate) async fn generate_sign_in_url_with_email(
&self,
authenticator: &AuthType,
@@ -682,6 +661,7 @@ impl UserManager {
Ok(url)
}
+ #[instrument(level = "info", skip_all)]
pub(crate) async fn sign_in_with_password(
&self,
email: &str,
@@ -695,6 +675,7 @@ impl UserManager {
Ok(response)
}
+ #[instrument(level = "info", skip_all)]
pub(crate) async fn sign_in_with_magic_link(
&self,
email: &str,
@@ -710,6 +691,7 @@ impl UserManager {
Ok(())
}
+ #[instrument(level = "info", skip_all)]
pub(crate) async fn sign_in_with_passcode(
&self,
email: &str,
@@ -723,6 +705,7 @@ impl UserManager {
Ok(response)
}
+ #[instrument(level = "info", skip_all)]
pub(crate) async fn generate_oauth_url(
&self,
oauth_provider: &str,
diff --git a/frontend/rust-lib/flowy-user/src/user_manager/manager_user_workspace.rs b/frontend/rust-lib/flowy-user/src/user_manager/manager_user_workspace.rs
index 6c786d9435..04e7e6b0d9 100644
--- a/frontend/rust-lib/flowy-user/src/user_manager/manager_user_workspace.rs
+++ b/frontend/rust-lib/flowy-user/src/user_manager/manager_user_workspace.rs
@@ -154,6 +154,8 @@ impl UserManager {
#[instrument(skip(self), err)]
pub async fn open_workspace(&self, workspace_id: &Uuid, auth_type: AuthType) -> FlowyResult<()> {
info!("open workspace: {}, auth_type:{}", workspace_id, auth_type);
+ self.cloud_service.set_server_auth_type(&auth_type);
+
let uid = self.user_id()?;
let conn = self.db_connection(self.user_id()?)?;
let user_workspace = match select_user_workspace(&workspace_id.to_string(), conn) {