From 65342a36a31f28fb9f8630e12a8794eb6b3eafc6 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Sun, 6 Jun 2021 17:09:32 +0200 Subject: [PATCH] fix: Set homeserver from localstorage in web --- lib/pages/homeserver_picker.dart | 20 +++++++++++++++----- lib/pages/sign_up.dart | 4 ++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/pages/homeserver_picker.dart b/lib/pages/homeserver_picker.dart index 34204f1f..e021e0e7 100644 --- a/lib/pages/homeserver_picker.dart +++ b/lib/pages/homeserver_picker.dart @@ -1,7 +1,9 @@ import 'dart:async'; import 'package:famedlysdk/famedlysdk.dart'; +import 'package:fluffychat/pages/sign_up.dart'; import 'package:fluffychat/pages/views/homeserver_picker_view.dart'; +import 'package:fluffychat/utils/famedlysdk_store.dart'; import 'package:fluffychat/widgets/matrix.dart'; import 'package:fluffychat/config/app_config.dart'; import 'package:fluffychat/config/setting_keys.dart'; @@ -31,13 +33,21 @@ class HomeserverPickerController extends State { void _loginWithToken(String token) { if (token?.isEmpty ?? true) return; + showFutureLoadingDialog( context: context, - future: () => Matrix.of(context).client.login( - type: AuthenticationTypes.token, - token: token, - initialDeviceDisplayName: PlatformInfos.clientName, - ), + future: () async { + if (Matrix.of(context).client.homeserver == null) { + await Matrix.of(context).client.checkHomeserver( + await Store().getItem(SignUpController.ssoHomeserverKey), + ); + } + await Matrix.of(context).client.login( + type: AuthenticationTypes.token, + token: token, + initialDeviceDisplayName: PlatformInfos.clientName, + ); + }, ); } diff --git a/lib/pages/sign_up.dart b/lib/pages/sign_up.dart index 5acbfb6e..e453b654 100644 --- a/lib/pages/sign_up.dart +++ b/lib/pages/sign_up.dart @@ -65,14 +65,14 @@ class SignUpController extends State { return _rawLoginTypes; } - static const String _ssoHomeserverKey = 'sso-homeserver'; + static const String ssoHomeserverKey = 'sso-homeserver'; void ssoLoginAction(String id) { if (kIsWeb) { // We store the homserver in the local storage instead of a redirect // parameter because of possible CSRF attacks. Store().setItem( - _ssoHomeserverKey, Matrix.of(context).client.homeserver.toString()); + ssoHomeserverKey, Matrix.of(context).client.homeserver.toString()); } final redirectUrl = kIsWeb ? html.window.location.href