From 48b7fc1592900eb3e2997e90e80cfb145cd6cd04 Mon Sep 17 00:00:00 2001 From: Airyz <36567925+Airyzz@users.noreply.github.com> Date: Sat, 29 Jun 2024 00:59:13 +0930 Subject: [PATCH] Fix sso-only server login --- commet/lib/client/matrix/matrix_client.dart | 8 +++- commet/lib/ui/pages/login/login_page.dart | 2 + .../lib/ui/pages/login/login_page_view.dart | 42 ++++++++++--------- 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/commet/lib/client/matrix/matrix_client.dart b/commet/lib/client/matrix/matrix_client.dart index e48c7910..f134deb3 100644 --- a/commet/lib/client/matrix/matrix_client.dart +++ b/commet/lib/client/matrix/matrix_client.dart @@ -274,7 +274,10 @@ class MatrixClient extends Client { "m.room.power_levels", "m.room.join_rules" }, - supportedLoginTypes: {matrix.AuthenticationTypes.password}, + supportedLoginTypes: { + matrix.AuthenticationTypes.password, + matrix.AuthenticationTypes.sso + }, nativeImplementations: nativeImplementations, databaseBuilder: (client) => getMatrixDatabase(client.clientName), logLevel: BuildConfig.RELEASE ? matrix.Level.warning : matrix.Level.info, @@ -574,7 +577,8 @@ class MatrixClient extends Client { true, resultFlows, ); - } catch (_) { + } catch (error, trace) { + Log.onError(error, trace); return (false, null); } } diff --git a/commet/lib/ui/pages/login/login_page.dart b/commet/lib/ui/pages/login/login_page.dart index c4c7ad93..427413e3 100644 --- a/commet/lib/ui/pages/login/login_page.dart +++ b/commet/lib/ui/pages/login/login_page.dart @@ -78,6 +78,8 @@ class LoginPageState extends State { isLoggingIn: isLoggingIn, loadingServerInfo: loadingServerInfo, hasSsoSupport: loginFlows?.whereType().isNotEmpty == true, + hasPasswordSupport: + loginFlows?.whereType().isNotEmpty == true, isServerValid: isServerValid, ); } diff --git a/commet/lib/ui/pages/login/login_page_view.dart b/commet/lib/ui/pages/login/login_page_view.dart index f51745b2..aa1f3d67 100644 --- a/commet/lib/ui/pages/login/login_page_view.dart +++ b/commet/lib/ui/pages/login/login_page_view.dart @@ -26,6 +26,7 @@ class LoginPageView extends StatefulWidget { this.loadingServerInfo = false, this.isServerValid = false, this.hasSsoSupport = false, + this.hasPasswordSupport = false, this.updateHomeserver}); final bool canNavigateBack; final bool isLoggingIn; @@ -35,6 +36,7 @@ class LoginPageView extends StatefulWidget { final bool loadingServerInfo; final bool isServerValid; final bool hasSsoSupport; + final bool hasPasswordSupport; final Future Function(SsoLoginFlow flow)? doSsoLogin; final Future Function( PasswordLoginFlow flow, String username, String password)? @@ -76,7 +78,6 @@ class _LoginPageViewState extends State { _onHomeserverTextUpdated(); }); } - super.initState(); } @@ -221,7 +222,7 @@ class _LoginPageViewState extends State { const SizedBox(height: 16), homeserverEntry(), const SizedBox(height: 16), - usenamePasswordLoginInputs(), + if (widget.hasPasswordSupport) usenamePasswordLoginInputs(), SizedBox( height: 15, child: Center( @@ -238,23 +239,24 @@ class _LoginPageViewState extends State { if (widget.hasSsoSupport) Column( children: [ - Row( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - const SizedBox( - width: 100, - height: 10, - child: tiamat.Seperator(), - ), - tiamat.Text.labelLow(CommonStrings.labelOr), - const SizedBox( - width: 100, - height: 10, - child: tiamat.Seperator(), - ), - ], - ), + if (widget.hasPasswordSupport) + Row( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + const SizedBox( + width: 100, + height: 10, + child: tiamat.Seperator(), + ), + tiamat.Text.labelLow(CommonStrings.labelOr), + const SizedBox( + width: 100, + height: 10, + child: tiamat.Seperator(), + ), + ], + ), Padding( padding: const EdgeInsets.all(8.0), child: Wrap( @@ -377,7 +379,7 @@ class _LoginPageViewState extends State { height: 50, child: SvgPicture.asset( "assets/images/app_icon/icon.svg", - theme: SvgTheme(currentColor: Theme.of(context).colorScheme.onPrimary), + theme: SvgTheme(currentColor: Theme.of(context).colorScheme.onSurface), ), ); }