fix: Set homeserver from localstorage in web

This commit is contained in:
Christian Pauly 2021-06-06 17:09:32 +02:00
parent cefa4be534
commit 65342a36a3
2 changed files with 17 additions and 7 deletions

View File

@ -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<HomeserverPicker> {
void _loginWithToken(String token) {
if (token?.isEmpty ?? true) return;
showFutureLoadingDialog(
context: context,
future: () => Matrix.of(context).client.login(
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,
),
);
},
);
}

View File

@ -65,14 +65,14 @@ class SignUpController extends State<SignUp> {
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