chore: remove authticator pb

This commit is contained in:
Nathan 2025-04-20 00:28:15 +08:00
parent 58f87b39aa
commit 2f5b494885
44 changed files with 134 additions and 168 deletions

View File

@ -202,8 +202,7 @@ class MobileViewBottomSheetBody extends StatelessWidget {
List<Widget> _buildPublishActions(BuildContext context) { List<Widget> _buildPublishActions(BuildContext context) {
final userProfile = context.read<MobileViewPageBloc>().state.userProfilePB; final userProfile = context.read<MobileViewPageBloc>().state.userProfilePB;
// the publish feature is only available for AppFlowy Cloud // the publish feature is only available for AppFlowy Cloud
if (userProfile == null || if (userProfile == null || userProfile.authType != AuthTypePB.Server) {
userProfile.authType != AuthenticatorPB.AppFlowyCloud) {
return []; return [];
} }

View File

@ -48,7 +48,7 @@ class HomePageSettingsPopupMenu extends StatelessWidget {
text: LocaleKeys.settings_popupMenuItem_settings.tr(), text: LocaleKeys.settings_popupMenuItem_settings.tr(),
), ),
// only show the member items in cloud mode // only show the member items in cloud mode
if (userProfile.authType == AuthenticatorPB.AppFlowyCloud) ...[ if (userProfile.authType == AuthTypePB.Server) ...[
const PopupMenuDivider(height: 0.5), const PopupMenuDivider(height: 0.5),
_buildItem( _buildItem(
value: _MobileSettingsPopupMenuItem.members, value: _MobileSettingsPopupMenuItem.members,

View File

@ -167,7 +167,7 @@ class _MobileSpaceTabState extends State<MobileSpaceTab>
children: [ children: [
MobileHomeSpace(userProfile: widget.userProfile), MobileHomeSpace(userProfile: widget.userProfile),
// only show ai chat button for cloud user // only show ai chat button for cloud user
if (widget.userProfile.authType == AuthenticatorPB.AppFlowyCloud) if (widget.userProfile.authType == AuthTypePB.Server)
Positioned( Positioned(
bottom: MediaQuery.of(context).padding.bottom + 16, bottom: MediaQuery.of(context).padding.bottom + 16,
left: 20, left: 20,

View File

@ -123,7 +123,7 @@ class _CreateWorkspaceButton extends StatelessWidget {
context.read<UserWorkspaceBloc>().add( context.read<UserWorkspaceBloc>().add(
UserWorkspaceEvent.createWorkspace( UserWorkspaceEvent.createWorkspace(
name, name,
AuthTypePB.CloudAuthType, AuthTypePB.Server,
), ),
); );
}, },

View File

@ -40,7 +40,7 @@ class UserSessionSettingGroup extends StatelessWidget {
// delete account button // delete account button
// only show the delete account button in cloud mode // only show the delete account button in cloud mode
if (userProfile.authType == AuthenticatorPB.AppFlowyCloud) ...[ if (userProfile.authType == AuthTypePB.Server) ...[
const VSpace(16.0), const VSpace(16.0),
MobileLogoutButton( MobileLogoutButton(
text: LocaleKeys.button_deleteAccount.tr(), text: LocaleKeys.button_deleteAccount.tr(),

View File

@ -48,7 +48,7 @@ class AIChatPage extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// if (userProfile.authenticator != AuthenticatorPB.AppFlowyCloud) { // if (userProfile.authenticator != AuthTypePB.Server) {
// return Center( // return Center(
// child: FlowyText( // child: FlowyText(
// LocaleKeys.chat_unsupportedCloudPrompt.tr(), // LocaleKeys.chat_unsupportedCloudPrompt.tr(),

View File

@ -31,7 +31,7 @@ class DatabaseSyncBloc extends Bloc<DatabaseSyncEvent, DatabaseSyncBlocState> {
emit( emit(
state.copyWith( state.copyWith(
shouldShowIndicator: shouldShowIndicator:
userProfile?.authType == AuthenticatorPB.AppFlowyCloud && userProfile?.authType == AuthTypePB.Server &&
databaseId != null, databaseId != null,
), ),
); );

View File

@ -21,8 +21,8 @@ import 'package:appflowy/shared/af_image.dart';
import 'package:appflowy/shared/flowy_gradient_colors.dart'; import 'package:appflowy/shared/flowy_gradient_colors.dart';
import 'package:appflowy/shared/icon_emoji_picker/flowy_icon_emoji_picker.dart'; import 'package:appflowy/shared/icon_emoji_picker/flowy_icon_emoji_picker.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/protobuf.dart'; import 'package:appflowy_backend/protobuf/flowy-database2/protobuf.dart';
import 'package:appflowy_backend/protobuf/flowy-user/auth.pbenum.dart';
import 'package:appflowy_backend/protobuf/flowy-user/user_profile.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_editor/appflowy_editor.dart' hide UploadImageMenu; import 'package:appflowy_editor/appflowy_editor.dart' hide UploadImageMenu;
import 'package:easy_localization/easy_localization.dart'; import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/theme_extension.dart'; import 'package:flowy_infra/theme_extension.dart';
@ -69,8 +69,7 @@ class RowBanner extends StatefulWidget {
class _RowBannerState extends State<RowBanner> { class _RowBannerState extends State<RowBanner> {
final _isHovering = ValueNotifier(false); final _isHovering = ValueNotifier(false);
late final isLocalMode = late final isLocalMode =
(widget.userProfile?.authType ?? AuthenticatorPB.Local) == (widget.userProfile?.authType ?? AuthTypePB.Local) == AuthTypePB.Local;
AuthenticatorPB.Local;
@override @override
void dispose() { void dispose() {

View File

@ -101,8 +101,8 @@ class DocumentBloc extends Bloc<DocumentEvent, DocumentState> {
bool get isLocalMode { bool get isLocalMode {
final userProfilePB = state.userProfilePB; final userProfilePB = state.userProfilePB;
final type = userProfilePB?.authType ?? AuthenticatorPB.Local; final type = userProfilePB?.authType ?? AuthTypePB.Local;
return type == AuthenticatorPB.Local; return type == AuthTypePB.Local;
} }
@override @override

View File

@ -31,8 +31,7 @@ class DocumentCollaboratorsBloc
final userProfile = result.fold((s) => s, (f) => null); final userProfile = result.fold((s) => s, (f) => null);
emit( emit(
state.copyWith( state.copyWith(
shouldShowIndicator: shouldShowIndicator: userProfile?.authType == AuthTypePB.Server,
userProfile?.authType == AuthenticatorPB.AppFlowyCloud,
), ),
); );
final deviceId = ApplicationInfo.deviceId; final deviceId = ApplicationInfo.deviceId;

View File

@ -30,8 +30,7 @@ class DocumentSyncBloc extends Bloc<DocumentSyncEvent, DocumentSyncBlocState> {
); );
emit( emit(
state.copyWith( state.copyWith(
shouldShowIndicator: shouldShowIndicator: userProfile?.authType == AuthTypePB.Server,
userProfile?.authType == AuthenticatorPB.AppFlowyCloud,
), ),
); );
_syncStateListener.start( _syncStateListener.start(

View File

@ -14,8 +14,8 @@ import 'package:appflowy_backend/dispatch/error.dart';
import 'package:appflowy_backend/log.dart'; import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/file_entities.pbenum.dart'; import 'package:appflowy_backend/protobuf/flowy-database2/file_entities.pbenum.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/media_entities.pb.dart'; import 'package:appflowy_backend/protobuf/flowy-database2/media_entities.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-user/auth.pbenum.dart';
import 'package:appflowy_backend/protobuf/flowy-user/user_profile.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:cross_file/cross_file.dart'; import 'package:cross_file/cross_file.dart';
import 'package:easy_localization/easy_localization.dart'; import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/file_picker/file_picker_impl.dart'; import 'package:flowy_infra/file_picker/file_picker_impl.dart';
@ -185,7 +185,7 @@ Future<void> insertLocalFile(
// Check upload type // Check upload type
final isLocalMode = final isLocalMode =
(userProfile?.authType ?? AuthenticatorPB.Local) == AuthenticatorPB.Local; (userProfile?.authType ?? AuthTypePB.Local) == AuthTypePB.Local;
String? path; String? path;
String? errorMsg; String? errorMsg;
@ -230,7 +230,7 @@ Future<void> insertLocalFiles(
// Check upload type // Check upload type
final isLocalMode = final isLocalMode =
(userProfile?.authType ?? AuthenticatorPB.Local) == AuthenticatorPB.Local; (userProfile?.authType ?? AuthTypePB.Local) == AuthTypePB.Local;
for (final file in files) { for (final file in files) {
final fileType = file.fileType.toMediaFileTypePB(); final fileType = file.fileType.toMediaFileTypePB();

View File

@ -225,8 +225,7 @@ class PageStyleCoverImage extends StatelessWidget {
(s) => s, (s) => s,
(f) => null, (f) => null,
); );
final isAppFlowyCloud = final isAppFlowyCloud = userProfile?.authType == AuthTypePB.Server;
userProfile?.authType == AuthenticatorPB.AppFlowyCloud;
final PageStyleCoverImageType type; final PageStyleCoverImageType type;
if (!isAppFlowyCloud) { if (!isAppFlowyCloud) {
result = await saveImageToLocalStorage(path); result = await saveImageToLocalStorage(path);

View File

@ -193,7 +193,7 @@ class ShareBloc extends Bloc<ShareEvent, ShareState> {
Future<void> _updatePublishStatus(Emitter<ShareState> emit) async { Future<void> _updatePublishStatus(Emitter<ShareState> emit) async {
final publishInfo = await ViewBackendService.getPublishInfo(view); final publishInfo = await ViewBackendService.getPublishInfo(view);
final enablePublish = await UserBackendService.getCurrentUserProfile().fold( final enablePublish = await UserBackendService.getCurrentUserProfile().fold(
(v) => v.authType == AuthenticatorPB.AppFlowyCloud, (v) => v.authType == AuthTypePB.Server,
(p) => false, (p) => false,
); );

View File

@ -13,7 +13,7 @@ import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/user/application/user_service.dart'; import 'package:appflowy/user/application/user_service.dart';
import 'package:appflowy/util/default_extensions.dart'; import 'package:appflowy/util/default_extensions.dart';
import 'package:appflowy_backend/log.dart'; import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-user/auth.pbenum.dart'; import 'package:appflowy_backend/protobuf/flowy-user/workspace.pb.dart';
import 'package:desktop_drop/desktop_drop.dart'; import 'package:desktop_drop/desktop_drop.dart';
import 'package:dotted_border/dotted_border.dart'; import 'package:dotted_border/dotted_border.dart';
import 'package:easy_localization/easy_localization.dart'; import 'package:easy_localization/easy_localization.dart';
@ -294,8 +294,8 @@ class _IconUploaderState extends State<IconUploader> {
(userProfile) => userProfile, (userProfile) => userProfile,
(l) => null, (l) => null,
); );
final isLocalMode = (userProfile?.authType ?? AuthenticatorPB.Local) == final isLocalMode =
AuthenticatorPB.Local; (userProfile?.authType ?? AuthTypePB.Local) == AuthTypePB.Local;
if (isLocalMode) { if (isLocalMode) {
result = await pickedImages.first.saveToLocal(); result = await pickedImages.first.saveToLocal();
} else { } else {

View File

@ -102,7 +102,7 @@ void _resolveUserDeps(GetIt getIt, IntegrationMode mode) {
case AuthenticatorType.local: case AuthenticatorType.local:
getIt.registerFactory<AuthService>( getIt.registerFactory<AuthService>(
() => BackendAuthService( () => BackendAuthService(
AuthenticatorPB.Local, AuthTypePB.Local,
), ),
); );
break; break;

View File

@ -112,7 +112,7 @@ class AppFlowyCloudDeepLink {
(_) async { (_) async {
final deviceId = await getDeviceId(); final deviceId = await getDeviceId();
final payload = OauthSignInPB( final payload = OauthSignInPB(
authenticator: AuthenticatorPB.AppFlowyCloud, authenticator: AuthTypePB.Server,
map: { map: {
AuthServiceMapKeys.signInURL: uri.toString(), AuthServiceMapKeys.signInURL: uri.toString(),
AuthServiceMapKeys.deviceId: deviceId, AuthServiceMapKeys.deviceId: deviceId,

View File

@ -18,7 +18,7 @@ class AppFlowyCloudAuthService implements AuthService {
AppFlowyCloudAuthService(); AppFlowyCloudAuthService();
final BackendAuthService _backendAuthService = BackendAuthService( final BackendAuthService _backendAuthService = BackendAuthService(
AuthenticatorPB.AppFlowyCloud, AuthTypePB.Server,
); );
@override @override

View File

@ -20,7 +20,7 @@ class AppFlowyCloudMockAuthService implements AuthService {
final String userEmail; final String userEmail;
final BackendAuthService _appFlowyAuthService = final BackendAuthService _appFlowyAuthService =
BackendAuthService(AuthenticatorPB.AppFlowyCloud); BackendAuthService(AuthTypePB.Server);
@override @override
Future<FlowyResult<UserProfilePB, FlowyError>> signUp({ Future<FlowyResult<UserProfilePB, FlowyError>> signUp({
@ -48,7 +48,7 @@ class AppFlowyCloudMockAuthService implements AuthService {
Map<String, String> params = const {}, Map<String, String> params = const {},
}) async { }) async {
final payload = SignInUrlPayloadPB.create() final payload = SignInUrlPayloadPB.create()
..authenticator = AuthenticatorPB.AppFlowyCloud ..authenticator = AuthTypePB.Server
// don't use nanoid here, the gotrue server will transform the email // don't use nanoid here, the gotrue server will transform the email
..email = userEmail; ..email = userEmail;
@ -58,7 +58,7 @@ class AppFlowyCloudMockAuthService implements AuthService {
return getSignInURLResult.fold( return getSignInURLResult.fold(
(urlPB) async { (urlPB) async {
final payload = OauthSignInPB( final payload = OauthSignInPB(
authenticator: AuthenticatorPB.AppFlowyCloud, authenticator: AuthTypePB.Server,
map: { map: {
AuthServiceMapKeys.signInURL: urlPB.signInUrl, AuthServiceMapKeys.signInURL: urlPB.signInUrl,
AuthServiceMapKeys.deviceId: deviceId, AuthServiceMapKeys.deviceId: deviceId,

View File

@ -6,6 +6,7 @@ import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-user/auth.pb.dart'; import 'package:appflowy_backend/protobuf/flowy-user/auth.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart' import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart'
show SignInPayloadPB, SignUpPayloadPB, UserProfilePB; show SignInPayloadPB, SignUpPayloadPB, UserProfilePB;
import 'package:appflowy_backend/protobuf/flowy-user/workspace.pb.dart';
import 'package:appflowy_result/appflowy_result.dart'; import 'package:appflowy_result/appflowy_result.dart';
import 'package:easy_localization/easy_localization.dart'; import 'package:easy_localization/easy_localization.dart';
@ -15,7 +16,7 @@ import 'device_id.dart';
class BackendAuthService implements AuthService { class BackendAuthService implements AuthService {
BackendAuthService(this.authType); BackendAuthService(this.authType);
final AuthenticatorPB authType; final AuthTypePB authType;
@override @override
Future<FlowyResult<GotrueTokenResponsePB, FlowyError>> Future<FlowyResult<GotrueTokenResponsePB, FlowyError>>
@ -71,7 +72,7 @@ class BackendAuthService implements AuthService {
..email = userEmail ..email = userEmail
..password = password ..password = password
// When sign up as guest, the auth type is always local. // When sign up as guest, the auth type is always local.
..authType = AuthenticatorPB.Local ..authType = AuthTypePB.Local
..deviceId = await getDeviceId(); ..deviceId = await getDeviceId();
final response = await UserEventSignUp(request).send().then( final response = await UserEventSignUp(request).send().then(
(value) => value, (value) => value,
@ -82,7 +83,7 @@ class BackendAuthService implements AuthService {
@override @override
Future<FlowyResult<UserProfilePB, FlowyError>> signUpWithOAuth({ Future<FlowyResult<UserProfilePB, FlowyError>> signUpWithOAuth({
required String platform, required String platform,
AuthenticatorPB authType = AuthenticatorPB.Local, AuthTypePB authType = AuthTypePB.Local,
Map<String, String> params = const {}, Map<String, String> params = const {},
}) async { }) async {
return FlowyResult.failure( return FlowyResult.failure(

View File

@ -4,8 +4,8 @@ import 'package:appflowy/env/cloud_env.dart';
import 'package:appflowy/user/application/password/password_http_service.dart'; import 'package:appflowy/user/application/password/password_http_service.dart';
import 'package:appflowy_backend/log.dart'; import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart'; import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-user/auth.pbenum.dart';
import 'package:appflowy_backend/protobuf/flowy-user/user_profile.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:appflowy_result/appflowy_result.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:freezed_annotation/freezed_annotation.dart';
@ -46,7 +46,7 @@ class PasswordBloc extends Bloc<PasswordEvent, PasswordState> {
bool _isInitialized = false; bool _isInitialized = false;
Future<void> _init() async { Future<void> _init() async {
if (userProfile.authType == AuthenticatorPB.Local) { if (userProfile.authType == AuthTypePB.Local) {
Log.debug('PasswordBloc: skip init because user is local authenticator'); Log.debug('PasswordBloc: skip init because user is local authenticator');
return; return;
} }

View File

@ -74,7 +74,7 @@ class AnonUserItem extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final icon = isSelected ? const FlowySvg(FlowySvgs.check_s) : null; final icon = isSelected ? const FlowySvg(FlowySvgs.check_s) : null;
final isDisabled = isSelected || user.authType != AuthenticatorPB.Local; final isDisabled = isSelected || user.authType != AuthTypePB.Local;
final desc = "${user.name}\t ${user.authType}\t"; final desc = "${user.name}\t ${user.authType}\t";
final child = SizedBox( final child = SizedBox(
height: 30, height: 30,

View File

@ -2,8 +2,6 @@ import 'package:appflowy/user/application/user_listener.dart';
import 'package:appflowy_backend/dispatch/dispatch.dart'; import 'package:appflowy_backend/dispatch/dispatch.dart';
import 'package:appflowy_backend/log.dart'; import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart'; import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-user/auth.pbenum.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_backend/protobuf/flowy-user/workspace.pb.dart';
import 'package:appflowy_result/appflowy_result.dart'; import 'package:appflowy_result/appflowy_result.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
@ -91,7 +89,7 @@ class SettingsDialogBloc
AFRolePB? currentWorkspaceMemberRole, AFRolePB? currentWorkspaceMemberRole,
]) async { ]) async {
if ([ if ([
AuthenticatorPB.Local, AuthTypePB.Local,
].contains(userProfile.authType)) { ].contains(userProfile.authType)) {
return false; return false;
} }

View File

@ -44,7 +44,7 @@ class UserWorkspaceBloc extends Bloc<UserWorkspaceEvent, UserWorkspaceState> {
final currentWorkspace = result.$1; final currentWorkspace = result.$1;
final workspaces = result.$2; final workspaces = result.$2;
final isCollabWorkspaceOn = final isCollabWorkspaceOn =
userProfile.authType == AuthenticatorPB.AppFlowyCloud && userProfile.authType == AuthTypePB.Server &&
FeatureFlag.collaborativeWorkspace.isOn; FeatureFlag.collaborativeWorkspace.isOn;
Log.info( Log.info(
'init workspace, current workspace: ${currentWorkspace?.workspaceId}, ' 'init workspace, current workspace: ${currentWorkspace?.workspaceId}, '

View File

@ -66,7 +66,7 @@ class WorkspaceBloc extends Bloc<WorkspaceEvent, WorkspaceState> {
Emitter<WorkspaceState> emit, Emitter<WorkspaceState> emit,
) async { ) async {
final result = final result =
await userService.createUserWorkspace(name, AuthTypePB.CloudAuthType); await userService.createUserWorkspace(name, AuthTypePB.Server);
emit( emit(
result.fold( result.fold(
(workspace) { (workspace) {

View File

@ -389,7 +389,7 @@ class _CreateWorkspaceButton extends StatelessWidget {
workspaceBloc.add( workspaceBloc.add(
UserWorkspaceEvent.createWorkspace( UserWorkspaceEvent.createWorkspace(
name, name,
AuthTypePB.CloudAuthType, AuthTypePB.Local,
), ),
); );
}, },

View File

@ -211,7 +211,7 @@ class ViewMoreActionTypeWrapper extends CustomActionCell {
) { ) {
final userProfile = context.read<SpaceBloc>().userProfile; final userProfile = context.read<SpaceBloc>().userProfile;
// move to feature doesn't support in local mode // move to feature doesn't support in local mode
if (userProfile.authType != AuthenticatorPB.AppFlowyCloud) { if (userProfile.authType != AuthTypePB.Server) {
return const SizedBox.shrink(); return const SizedBox.shrink();
} }
return BlocProvider.value( return BlocProvider.value(

View File

@ -7,8 +7,8 @@ import 'package:appflowy/workspace/presentation/settings/pages/account/account.d
import 'package:appflowy/workspace/presentation/settings/pages/account/email/email_section.dart'; import 'package:appflowy/workspace/presentation/settings/pages/account/email/email_section.dart';
import 'package:appflowy/workspace/presentation/settings/shared/settings_body.dart'; import 'package:appflowy/workspace/presentation/settings/shared/settings_body.dart';
import 'package:appflowy/workspace/presentation/settings/shared/settings_category.dart'; import 'package:appflowy/workspace/presentation/settings/shared/settings_category.dart';
import 'package:appflowy_backend/protobuf/flowy-user/auth.pbenum.dart';
import 'package:appflowy_backend/protobuf/flowy-user/user_profile.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:easy_localization/easy_localization.dart'; import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
@ -70,7 +70,7 @@ class _SettingsAccountViewState extends State<SettingsAccountView> {
// user email // user email
// Only show email if the user is authenticated and not using local auth // Only show email if the user is authenticated and not using local auth
if (isAuthEnabled && if (isAuthEnabled &&
state.userProfile.authType != AuthenticatorPB.Local) ...[ state.userProfile.authType != AuthTypePB.Local) ...[
SettingsCategory( SettingsCategory(
title: LocaleKeys.newSettings_myAccount_myAccount.tr(), title: LocaleKeys.newSettings_myAccount_myAccount.tr(),
children: [ children: [
@ -82,30 +82,26 @@ class _SettingsAccountViewState extends State<SettingsAccountView> {
), ),
AccountSignInOutSection( AccountSignInOutSection(
userProfile: state.userProfile, userProfile: state.userProfile,
onAction: onAction: state.userProfile.authType == AuthTypePB.Local
state.userProfile.authType == AuthenticatorPB.Local
? widget.didLogin ? widget.didLogin
: widget.didLogout, : widget.didLogout,
signIn: signIn: state.userProfile.authType == AuthTypePB.Local,
state.userProfile.authType == AuthenticatorPB.Local,
), ),
], ],
), ),
], ],
if (isAuthEnabled && if (isAuthEnabled &&
state.userProfile.authType == AuthenticatorPB.Local) ...[ state.userProfile.authType == AuthTypePB.Local) ...[
SettingsCategory( SettingsCategory(
title: LocaleKeys.settings_accountPage_login_title.tr(), title: LocaleKeys.settings_accountPage_login_title.tr(),
children: [ children: [
AccountSignInOutSection( AccountSignInOutSection(
userProfile: state.userProfile, userProfile: state.userProfile,
onAction: onAction: state.userProfile.authType == AuthTypePB.Local
state.userProfile.authType == AuthenticatorPB.Local
? widget.didLogin ? widget.didLogin
: widget.didLogout, : widget.didLogout,
signIn: signIn: state.userProfile.authType == AuthTypePB.Local,
state.userProfile.authType == AuthenticatorPB.Local,
), ),
], ],
), ),
@ -120,7 +116,7 @@ class _SettingsAccountViewState extends State<SettingsAccountView> {
), ),
// user deletion // user deletion
if (widget.userProfile.authType == AuthenticatorPB.AppFlowyCloud) if (widget.userProfile.authType == AuthTypePB.Server)
const AccountDeletionButton(), const AccountDeletionButton(),
], ],
); );

View File

@ -88,7 +88,7 @@ class SettingsWorkspaceView extends StatelessWidget {
autoSeparate: false, autoSeparate: false,
children: [ children: [
// We don't allow changing workspace name/icon for local/offline // We don't allow changing workspace name/icon for local/offline
if (userProfile.authType != AuthenticatorPB.Local) ...[ if (userProfile.authType != AuthTypePB.Local) ...[
SettingsCategory( SettingsCategory(
title: LocaleKeys.settings_workspacePage_workspaceName_title title: LocaleKeys.settings_workspacePage_workspaceName_title
.tr(), .tr(),
@ -180,7 +180,7 @@ class SettingsWorkspaceView extends StatelessWidget {
), ),
const SettingsCategorySpacer(), const SettingsCategorySpacer(),
if (userProfile.authType != AuthenticatorPB.Local) ...[ if (userProfile.authType != AuthTypePB.Local) ...[
SingleSettingAction( SingleSettingAction(
label: LocaleKeys.settings_workspacePage_manageWorkspace_title label: LocaleKeys.settings_workspacePage_manageWorkspace_title
.tr(), .tr(),

View File

@ -140,7 +140,7 @@ class SettingsDialog extends StatelessWidget {
case SettingsPage.shortcuts: case SettingsPage.shortcuts:
return const SettingsShortcutsView(); return const SettingsShortcutsView();
case SettingsPage.ai: case SettingsPage.ai:
if (user.authType == AuthenticatorPB.AppFlowyCloud) { if (user.authType == AuthTypePB.Server) {
return SettingsAIView( return SettingsAIView(
key: ValueKey(workspaceId), key: ValueKey(workspaceId),
userProfile: user, userProfile: user,

View File

@ -63,7 +63,7 @@ class SettingsMenu extends StatelessWidget {
changeSelectedPage: changeSelectedPage, changeSelectedPage: changeSelectedPage,
), ),
if (FeatureFlag.membersSettings.isOn && if (FeatureFlag.membersSettings.isOn &&
userProfile.authType == AuthenticatorPB.AppFlowyCloud) userProfile.authType == AuthTypePB.Server)
SettingsMenuElement( SettingsMenuElement(
page: SettingsPage.member, page: SettingsPage.member,
selectedPage: currentPage, selectedPage: currentPage,
@ -109,7 +109,7 @@ class SettingsMenu extends StatelessWidget {
), ),
changeSelectedPage: changeSelectedPage, changeSelectedPage: changeSelectedPage,
), ),
if (userProfile.authType == AuthenticatorPB.AppFlowyCloud) if (userProfile.authType == AuthTypePB.Server)
SettingsMenuElement( SettingsMenuElement(
page: SettingsPage.sites, page: SettingsPage.sites,
selectedPage: currentPage, selectedPage: currentPage,

View File

@ -96,7 +96,7 @@ class _MoreViewActionsState extends State<MoreViewActions> {
return BlocBuilder<SpaceBloc, SpaceState>( return BlocBuilder<SpaceBloc, SpaceState>(
builder: (context, state) { builder: (context, state) {
if (state.spaces.isEmpty && if (state.spaces.isEmpty &&
userProfile.authType == AuthenticatorPB.AppFlowyCloud) { userProfile.authType == AuthTypePB.Server) {
return const SizedBox.shrink(); return const SizedBox.shrink();
} }

View File

@ -8,7 +8,7 @@ use collab_entity::CollabType;
use flowy_core::config::AppFlowyCoreConfig; use flowy_core::config::AppFlowyCoreConfig;
use flowy_core::AppFlowyCore; use flowy_core::AppFlowyCore;
use flowy_notification::register_notification_sender; use flowy_notification::register_notification_sender;
use flowy_user::entities::AuthenticatorPB; use flowy_user::entities::AuthTypePB;
use flowy_user::errors::FlowyError; use flowy_user::errors::FlowyError;
use lib_dispatch::runtime::AFPluginRuntime; use lib_dispatch::runtime::AFPluginRuntime;
use nanoid::nanoid; use nanoid::nanoid;
@ -59,7 +59,7 @@ impl EventIntegrationTest {
let clean_path = config.storage_path.clone(); let clean_path = config.storage_path.clone();
let inner = init_core(config).await; let inner = init_core(config).await;
let notification_sender = TestNotificationSender::new(); let notification_sender = TestNotificationSender::new();
let authenticator = Arc::new(AtomicU8::new(AuthenticatorPB::Local as u8)); let authenticator = Arc::new(AtomicU8::new(AuthTypePB::Local as u8));
register_notification_sender(notification_sender.clone()); register_notification_sender(notification_sender.clone());
// In case of dropping the runtime that runs the core, we need to forget the dispatcher // In case of dropping the runtime that runs the core, we need to forget the dispatcher

View File

@ -17,7 +17,7 @@ use flowy_server::af_cloud::define::{USER_DEVICE_ID, USER_EMAIL, USER_SIGN_IN_UR
use flowy_server_pub::af_cloud_config::AFCloudConfiguration; use flowy_server_pub::af_cloud_config::AFCloudConfiguration;
use flowy_server_pub::AuthenticatorType; use flowy_server_pub::AuthenticatorType;
use flowy_user::entities::{ use flowy_user::entities::{
AuthTypePB, AuthenticatorPB, ChangeWorkspaceIconPB, CloudSettingPB, CreateWorkspacePB, AuthTypePB, AuthTypePB, ChangeWorkspaceIconPB, CloudSettingPB, CreateWorkspacePB,
ImportAppFlowyDataPB, OauthSignInPB, OpenUserWorkspacePB, RenameWorkspacePB, ImportAppFlowyDataPB, OauthSignInPB, OpenUserWorkspacePB, RenameWorkspacePB,
RepeatedUserWorkspacePB, SignInUrlPB, SignInUrlPayloadPB, SignUpPayloadPB, UpdateCloudConfigPB, RepeatedUserWorkspacePB, SignInUrlPB, SignInUrlPayloadPB, SignUpPayloadPB, UpdateCloudConfigPB,
UpdateUserProfilePayloadPB, UserProfilePB, UserWorkspaceIdPB, UserWorkspacePB, UpdateUserProfilePayloadPB, UserProfilePB, UserWorkspaceIdPB, UserWorkspacePB,
@ -65,7 +65,7 @@ impl EventIntegrationTest {
email, email,
name: "appflowy".to_string(), name: "appflowy".to_string(),
password: password.clone(), password: password.clone(),
auth_type: AuthenticatorPB::Local, auth_type: AuthTypePB::Local,
device_id: uuid::Uuid::new_v4().to_string(), device_id: uuid::Uuid::new_v4().to_string(),
} }
.into_bytes() .into_bytes()
@ -113,7 +113,7 @@ impl EventIntegrationTest {
.await; .await;
} }
pub fn set_auth_type(&self, auth_type: AuthenticatorPB) { pub fn set_auth_type(&self, auth_type: AuthTypePB) {
self.authenticator.store(auth_type as u8, Ordering::Release); self.authenticator.store(auth_type as u8, Ordering::Release);
} }
@ -140,7 +140,7 @@ impl EventIntegrationTest {
pub async fn af_cloud_sign_in_with_email(&self, email: &str) -> FlowyResult<UserProfilePB> { pub async fn af_cloud_sign_in_with_email(&self, email: &str) -> FlowyResult<UserProfilePB> {
let payload = SignInUrlPayloadPB { let payload = SignInUrlPayloadPB {
email: email.to_string(), email: email.to_string(),
authenticator: AuthenticatorPB::AppFlowyCloud, authenticator: AuthTypePB::AppFlowyCloud,
}; };
let sign_in_url = EventBuilder::new(self.clone()) let sign_in_url = EventBuilder::new(self.clone())
.event(UserEvent::GenerateSignInURL) .event(UserEvent::GenerateSignInURL)
@ -155,7 +155,7 @@ impl EventIntegrationTest {
map.insert(USER_DEVICE_ID.to_string(), Uuid::new_v4().to_string()); map.insert(USER_DEVICE_ID.to_string(), Uuid::new_v4().to_string());
let payload = OauthSignInPB { let payload = OauthSignInPB {
map, map,
authenticator: AuthenticatorPB::AppFlowyCloud, authenticator: AuthTypePB::AppFlowyCloud,
}; };
let user_profile = EventBuilder::new(self.clone()) let user_profile = EventBuilder::new(self.clone())

View File

@ -1,7 +1,7 @@
use event_integration_test::user_event::use_localhost_af_cloud; use event_integration_test::user_event::use_localhost_af_cloud;
use event_integration_test::EventIntegrationTest; use event_integration_test::EventIntegrationTest;
use flowy_core::DEFAULT_NAME; use flowy_core::DEFAULT_NAME;
use flowy_user::entities::AuthenticatorPB; use flowy_user::entities::AuthTypePB;
use crate::util::unzip; use crate::util::unzip;
@ -72,7 +72,7 @@ async fn migrate_anon_user_data_to_af_cloud_test() {
let user = test.af_cloud_sign_up().await; let user = test.af_cloud_sign_up().await;
let workspace = test.get_current_workspace().await; let workspace = test.get_current_workspace().await;
println!("user workspace: {:?}", workspace.id); println!("user workspace: {:?}", workspace.id);
assert_eq!(user.auth_type, AuthenticatorPB::AppFlowyCloud); assert_eq!(user.auth_type, AuthTypePB::AppFlowyCloud);
let user_first_level_views = test.get_all_workspace_views().await; let user_first_level_views = test.get_all_workspace_views().await;
assert_eq!(user_first_level_views.len(), 3); assert_eq!(user_first_level_views.len(), 3);

View File

@ -1,6 +1,6 @@
use event_integration_test::user_event::{login_password, unique_email}; use event_integration_test::user_event::{login_password, unique_email};
use event_integration_test::{event_builder::EventBuilder, EventIntegrationTest}; use event_integration_test::{event_builder::EventBuilder, EventIntegrationTest};
use flowy_user::entities::{AuthenticatorPB, SignInPayloadPB, SignUpPayloadPB}; use flowy_user::entities::{AuthTypePB, SignInPayloadPB, SignUpPayloadPB};
use flowy_user::errors::ErrorCode; use flowy_user::errors::ErrorCode;
use flowy_user::event_map::UserEvent::*; use flowy_user::event_map::UserEvent::*;
@ -14,7 +14,7 @@ async fn sign_up_with_invalid_email() {
email: email.to_string(), email: email.to_string(),
name: valid_name(), name: valid_name(),
password: login_password(), password: login_password(),
auth_type: AuthenticatorPB::Local, auth_type: AuthTypePB::Local,
device_id: "".to_string(), device_id: "".to_string(),
}; };
@ -40,7 +40,7 @@ async fn sign_in_with_invalid_email() {
email: email.to_string(), email: email.to_string(),
password: login_password(), password: login_password(),
name: "".to_string(), name: "".to_string(),
auth_type: AuthenticatorPB::Local, auth_type: AuthTypePB::Local,
device_id: "".to_string(), device_id: "".to_string(),
}; };
@ -67,7 +67,7 @@ async fn sign_in_with_invalid_password() {
email: unique_email(), email: unique_email(),
password, password,
name: "".to_string(), name: "".to_string(),
auth_type: AuthenticatorPB::Local, auth_type: AuthTypePB::Local,
device_id: "".to_string(), device_id: "".to_string(),
}; };

View File

@ -1,6 +1,6 @@
use crate::user::local_test::helper::*; use crate::user::local_test::helper::*;
use event_integration_test::{event_builder::EventBuilder, EventIntegrationTest}; use event_integration_test::{event_builder::EventBuilder, EventIntegrationTest};
use flowy_user::entities::{AuthenticatorPB, UpdateUserProfilePayloadPB, UserProfilePB}; use flowy_user::entities::{AuthTypePB, UpdateUserProfilePayloadPB, UserProfilePB};
use flowy_user::{errors::ErrorCode, event_map::UserEvent::*}; use flowy_user::{errors::ErrorCode, event_map::UserEvent::*};
use nanoid::nanoid; use nanoid::nanoid;
#[tokio::test] #[tokio::test]
@ -24,7 +24,7 @@ async fn anon_user_profile_get() {
.await .await
.parse::<UserProfilePB>(); .parse::<UserProfilePB>();
assert_eq!(user_profile.id, user.id); assert_eq!(user_profile.id, user.id);
assert_eq!(user_profile.auth_type, AuthenticatorPB::Local); assert_eq!(user_profile.auth_type, AuthTypePB::Local);
} }
#[tokio::test] #[tokio::test]

View File

@ -35,7 +35,7 @@ impl UserCloudService for LocalServerUserServiceImpl {
let params = params.unbox_or_error::<SignUpParams>()?; let params = params.unbox_or_error::<SignUpParams>()?;
let uid = ID_GEN.lock().await.next_id(); let uid = ID_GEN.lock().await.next_id();
let workspace_id = Uuid::new_v4().to_string(); let workspace_id = Uuid::new_v4().to_string();
let user_workspace = UserWorkspace::new_local(&workspace_id, uid); let user_workspace = UserWorkspace::new_local(workspace_id, "");
let user_name = if params.name.is_empty() { let user_name = if params.name.is_empty() {
DEFAULT_USER_NAME() DEFAULT_USER_NAME()
} else { } else {
@ -59,7 +59,9 @@ impl UserCloudService for LocalServerUserServiceImpl {
async fn sign_in(&self, params: BoxAny) -> Result<AuthResponse, FlowyError> { async fn sign_in(&self, params: BoxAny) -> Result<AuthResponse, FlowyError> {
let params: SignInParams = params.unbox_or_error::<SignInParams>()?; let params: SignInParams = params.unbox_or_error::<SignInParams>()?;
let uid = ID_GEN.lock().await.next_id(); let uid = ID_GEN.lock().await.next_id();
let user_workspace = make_user_workspace("My Workspace");
let workspace_id = Uuid::new_v4();
let user_workspace = UserWorkspace::new_local(workspace_id.to_string(), "My Workspace");
Ok(AuthResponse { Ok(AuthResponse {
user_id: uid, user_id: uid,
user_uuid: Uuid::new_v4(), user_uuid: Uuid::new_v4(),
@ -143,7 +145,11 @@ impl UserCloudService for LocalServerUserServiceImpl {
} }
async fn create_workspace(&self, workspace_name: &str) -> Result<UserWorkspace, FlowyError> { async fn create_workspace(&self, workspace_name: &str) -> Result<UserWorkspace, FlowyError> {
Ok(make_user_workspace(workspace_name)) let workspace_id = Uuid::new_v4();
Ok(UserWorkspace::new_local(
workspace_id.to_string(),
workspace_name,
))
} }
async fn patch_workspace( async fn patch_workspace(
@ -192,15 +198,3 @@ impl UserCloudService for LocalServerUserServiceImpl {
Ok(()) Ok(())
} }
} }
fn make_user_workspace(name: &str) -> UserWorkspace {
UserWorkspace {
id: Uuid::new_v4().to_string(),
name: name.to_string(),
created_at: Default::default(),
workspace_database_id: Uuid::new_v4().to_string(),
icon: "".to_string(),
member_count: 1,
role: None,
}
}

View File

@ -122,10 +122,10 @@ impl UserWorkspace {
Ok(id) Ok(id)
} }
pub fn new_local(workspace_id: &str, _uid: i64) -> Self { pub fn new_local(workspace_id: String, name: &str) -> Self {
Self { Self {
id: workspace_id.to_string(), id: workspace_id,
name: "".to_string(), name: name.to_string(),
created_at: Utc::now(), created_at: Utc::now(),
workspace_database_id: Uuid::new_v4().to_string(), workspace_database_id: Uuid::new_v4().to_string(),
icon: "".to_string(), icon: "".to_string(),

View File

@ -93,20 +93,20 @@ pub fn upsert_user_workspace(
user_workspace: UserWorkspace, user_workspace: UserWorkspace,
conn: &mut SqliteConnection, conn: &mut SqliteConnection,
) -> Result<(), FlowyError> { ) -> Result<(), FlowyError> {
let new_record = UserWorkspaceTable::from_workspace(uid, &user_workspace, auth_type)?; let row = UserWorkspaceTable::from_workspace(uid, &user_workspace, auth_type)?;
diesel::insert_into(user_workspace_table::table) diesel::insert_into(user_workspace_table::table)
.values(new_record.clone()) .values(row.clone())
.on_conflict(user_workspace_table::id) .on_conflict(user_workspace_table::id)
.do_update() .do_update()
.set(( .set((
user_workspace_table::name.eq(new_record.name), user_workspace_table::name.eq(row.name),
user_workspace_table::uid.eq(new_record.uid), user_workspace_table::uid.eq(row.uid),
user_workspace_table::created_at.eq(new_record.created_at), user_workspace_table::created_at.eq(row.created_at),
user_workspace_table::database_storage_id.eq(new_record.database_storage_id), user_workspace_table::database_storage_id.eq(row.database_storage_id),
user_workspace_table::icon.eq(new_record.icon), user_workspace_table::icon.eq(row.icon),
user_workspace_table::member_count.eq(new_record.member_count), user_workspace_table::member_count.eq(row.member_count),
user_workspace_table::role.eq(new_record.role), user_workspace_table::role.eq(row.role),
user_workspace_table::auth_type.eq(new_record.auth_type), user_workspace_table::auth_type.eq(row.auth_type),
)) ))
.execute(conn)?; .execute(conn)?;

View File

@ -1,13 +1,13 @@
use std::collections::HashMap; use std::collections::HashMap;
use std::convert::TryInto; use std::convert::TryInto;
use crate::entities::parser::*;
use crate::entities::AuthTypePB;
use crate::errors::ErrorCode;
use client_api::entity::GotrueTokenResponse; use client_api::entity::GotrueTokenResponse;
use flowy_derive::{ProtoBuf, ProtoBuf_Enum}; use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
use flowy_user_pub::entities::*; use flowy_user_pub::entities::*;
use crate::entities::parser::*;
use crate::errors::ErrorCode;
#[derive(ProtoBuf, Default)] #[derive(ProtoBuf, Default)]
pub struct SignInPayloadPB { pub struct SignInPayloadPB {
#[pb(index = 1)] #[pb(index = 1)]
@ -20,7 +20,7 @@ pub struct SignInPayloadPB {
pub name: String, pub name: String,
#[pb(index = 4)] #[pb(index = 4)]
pub auth_type: AuthenticatorPB, pub auth_type: AuthTypePB,
#[pb(index = 5)] #[pb(index = 5)]
pub device_id: String, pub device_id: String,
@ -53,7 +53,7 @@ pub struct SignUpPayloadPB {
pub password: String, pub password: String,
#[pb(index = 4)] #[pb(index = 4)]
pub auth_type: AuthenticatorPB, pub auth_type: AuthTypePB,
#[pb(index = 5)] #[pb(index = 5)]
pub device_id: String, pub device_id: String,
@ -144,7 +144,7 @@ pub struct OauthSignInPB {
pub map: HashMap<String, String>, pub map: HashMap<String, String>,
#[pb(index = 2)] #[pb(index = 2)]
pub authenticator: AuthenticatorPB, pub authenticator: AuthTypePB,
} }
#[derive(ProtoBuf, Default)] #[derive(ProtoBuf, Default)]
@ -153,7 +153,7 @@ pub struct SignInUrlPayloadPB {
pub email: String, pub email: String,
#[pb(index = 2)] #[pb(index = 2)]
pub authenticator: AuthenticatorPB, pub authenticator: AuthTypePB,
} }
#[derive(ProtoBuf, Default)] #[derive(ProtoBuf, Default)]
@ -228,41 +228,10 @@ pub struct OauthProviderDataPB {
pub oauth_url: String, pub oauth_url: String,
} }
#[repr(u8)]
#[derive(ProtoBuf_Enum, Eq, PartialEq, Debug, Clone)]
pub enum AuthenticatorPB {
Local = 0,
AppFlowyCloud = 2,
}
impl From<AuthType> for AuthenticatorPB {
fn from(auth_type: AuthType) -> Self {
match auth_type {
AuthType::Local => AuthenticatorPB::Local,
AuthType::AppFlowyCloud => AuthenticatorPB::AppFlowyCloud,
}
}
}
impl From<AuthenticatorPB> for AuthType {
fn from(pb: AuthenticatorPB) -> Self {
match pb {
AuthenticatorPB::Local => AuthType::Local,
AuthenticatorPB::AppFlowyCloud => AuthType::AppFlowyCloud,
}
}
}
impl Default for AuthenticatorPB {
fn default() -> Self {
Self::Local
}
}
#[derive(Default, ProtoBuf)] #[derive(Default, ProtoBuf)]
pub struct UserStatePB { pub struct UserStatePB {
#[pb(index = 1)] #[pb(index = 1)]
pub auth_type: AuthenticatorPB, pub auth_type: AuthTypePB,
} }
#[derive(ProtoBuf, Debug, Default, Clone)] #[derive(ProtoBuf, Debug, Default, Clone)]

View File

@ -1,6 +1,6 @@
use super::AFRolePB; use super::AFRolePB;
use crate::entities::parser::{UserEmail, UserIcon, UserName}; use crate::entities::parser::{UserEmail, UserIcon, UserName};
use crate::entities::{AuthTypePB, AuthenticatorPB}; use crate::entities::AuthTypePB;
use crate::errors::ErrorCode; use crate::errors::ErrorCode;
use flowy_derive::{ProtoBuf, ProtoBuf_Enum}; use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
use flowy_user_pub::entities::*; use flowy_user_pub::entities::*;
@ -39,7 +39,7 @@ pub struct UserProfilePB {
pub icon_url: String, pub icon_url: String,
#[pb(index = 6)] #[pb(index = 6)]
pub auth_type: AuthenticatorPB, pub auth_type: AuthTypePB,
} }
#[derive(ProtoBuf_Enum, Eq, PartialEq, Debug, Clone)] #[derive(ProtoBuf_Enum, Eq, PartialEq, Debug, Clone)]

View File

@ -242,18 +242,23 @@ pub struct CreateWorkspacePB {
pub auth_type: AuthTypePB, pub auth_type: AuthTypePB,
} }
#[derive(ProtoBuf_Enum, Default, Debug, Clone)] #[derive(ProtoBuf_Enum, Default, Debug, Clone, Eq, PartialEq)]
#[repr(u8)]
pub enum AuthTypePB { pub enum AuthTypePB {
LocalAuthType = 0,
#[default] #[default]
CloudAuthType = 1, Local = 0,
Server = 1,
} }
impl From<i32> for AuthTypePB { impl From<i32> for AuthTypePB {
fn from(value: i32) -> Self { fn from(value: i32) -> Self {
match value { match value {
0 => AuthTypePB::LocalAuthType, 0 => AuthTypePB::Local,
1 => AuthTypePB::CloudAuthType, 1 => AuthTypePB::Server,
_ => AuthTypePB::CloudAuthType, // For historical reasons, 2 also maps to Server.
// Check the AuthenticatorType in flowy-server-pub
2 => AuthTypePB::Server,
_ => AuthTypePB::Server,
} }
} }
} }
@ -261,8 +266,8 @@ impl From<i32> for AuthTypePB {
impl From<AuthType> for AuthTypePB { impl From<AuthType> for AuthTypePB {
fn from(value: AuthType) -> Self { fn from(value: AuthType) -> Self {
match value { match value {
AuthType::Local => AuthTypePB::LocalAuthType, AuthType::Local => AuthTypePB::Local,
AuthType::AppFlowyCloud => AuthTypePB::CloudAuthType, AuthType::AppFlowyCloud => AuthTypePB::Server,
} }
} }
} }
@ -270,8 +275,8 @@ impl From<AuthType> for AuthTypePB {
impl From<AuthTypePB> for AuthType { impl From<AuthTypePB> for AuthType {
fn from(value: AuthTypePB) -> Self { fn from(value: AuthTypePB) -> Self {
match value { match value {
AuthTypePB::LocalAuthType => AuthType::Local, AuthTypePB::Local => AuthType::Local,
AuthTypePB::CloudAuthType => AuthType::AppFlowyCloud, AuthTypePB::Server => AuthType::AppFlowyCloud,
} }
} }
} }

View File

@ -218,15 +218,23 @@ impl UserManager {
workspace_name: &str, workspace_name: &str,
auth_type: AuthType, auth_type: AuthType,
) -> FlowyResult<UserWorkspace> { ) -> FlowyResult<UserWorkspace> {
let new_workspace = self let new_workspace = match auth_type {
AuthType::Local => {
let workspace_id = Uuid::new_v4();
UserWorkspace::new_local(workspace_id.to_string(), workspace_name)
},
AuthType::AppFlowyCloud => {
self
.cloud_service .cloud_service
.get_user_service()? .get_user_service()?
.create_workspace(workspace_name) .create_workspace(workspace_name)
.await?; .await?
},
};
info!( info!(
"new workspace: {}, name:{}", "create workspace: {}, name:{}, auth_type: {}",
new_workspace.id, new_workspace.name new_workspace.id, new_workspace.name, auth_type
); );
// save the workspace to sqlite db // save the workspace to sqlite db