Skip to content

Commit

Permalink
Handle error for Twake welcome screen
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhhdev committed Jun 10, 2024
1 parent bbe372d commit b93a184
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 33 deletions.
4 changes: 2 additions & 2 deletions lib/pages/bootstrap/bootstrap_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class BootstrapDialogState extends State<BootstrapDialog> {
centerTitle: true,
leading: IconButton(
icon: const Icon(Icons.close),
onPressed: Navigator.of(context).pop,
onPressed: () => Navigator.of(context).pop(false),
),
title: Text(L10n.of(context)!.recoveryKey),
),
Expand Down Expand Up @@ -233,7 +233,7 @@ class BootstrapDialogState extends State<BootstrapDialog> {
centerTitle: true,
leading: IconButton(
icon: const Icon(Icons.close),
onPressed: Navigator.of(context).pop,
onPressed: () => Navigator.of(context).pop(false),
),
title: Text(L10n.of(context)!.chatBackup),
),
Expand Down
4 changes: 2 additions & 2 deletions lib/pages/bootstrap/tom_bootstrap_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class TomBootstrapDialogState extends State<TomBootstrapDialog>
Logs().d(
'TomBootstrapDialog::_initializeRecoveryKeyState(): no recovery existed then call bootstrap',
);
Navigator.pop(context);
Navigator.of(context, rootNavigator: false).pop<bool>(false);
await BootstrapDialog(client: widget.client).show();
}
}
Expand Down Expand Up @@ -197,7 +197,7 @@ class TomBootstrapDialogState extends State<TomBootstrapDialog>
break;
case UploadRecoveryKeyState.unlockError:
WidgetsBinding.instance.addPostFrameCallback((_) async {
Navigator.pop(context);
Navigator.of(context, rootNavigator: false).pop<bool>(false);
await BootstrapDialog(client: widget.client).show();
});
break;
Expand Down
36 changes: 21 additions & 15 deletions lib/pages/twake_welcome/twake_welcome.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:fluffychat/config/app_config.dart';
import 'package:equatable/equatable.dart';
import 'package:fluffychat/presentation/mixins/connect_page_mixin.dart';
Expand Down Expand Up @@ -68,21 +70,25 @@ class TwakeWelcomeController extends State<TwakeWelcome> with ConnectPageMixin {
}

void _redirectRegistrationUrl(String url) async {
final homeserverExisted = await _homeserverExisted();
if (homeserverExisted) return;
matrix.loginHomeserverSummary =
await matrix.getLoginClient().checkHomeserver(
Uri.parse(AppConfig.twakeWorkplaceHomeserver),
);
final uri = await FlutterWebAuth2.authenticate(
url: url,
callbackUrlScheme: AppConfig.appOpenUrlScheme,
options: const FlutterWebAuth2Options(
intentFlags: ephemeralIntentFlags,
),
);
Logs().d("TwakeIdController:_redirectRegistrationUrl: URI - $uri");
handleTokenFromRegistrationSite(matrix: matrix, uri: uri);
try {
final homeserverExisted = await _homeserverExisted();
if (homeserverExisted) return;
matrix.loginHomeserverSummary =
await matrix.getLoginClient().checkHomeserver(
Uri.parse(AppConfig.twakeWorkplaceHomeserver),
);
final uri = await FlutterWebAuth2.authenticate(
url: url,
callbackUrlScheme: AppConfig.appOpenUrlScheme,
options: const FlutterWebAuth2Options(
intentFlags: ephemeralIntentFlags,
),
);
Logs().d("TwakeIdController:_redirectRegistrationUrl: URI - $uri");
await handleTokenFromRegistrationSite(matrix: matrix, uri: uri);
} catch (e) {
Logs().e("TwakeIdController::_redirectRegistrationUrl: $e");
}
}

void onClickCreateTwakeId() {
Expand Down
45 changes: 31 additions & 14 deletions lib/presentation/mixins/connect_page_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -254,23 +254,40 @@ mixin ConnectPageMixin {
return list;
}

void handleTokenFromRegistrationSite({
Future<SsoLoginState> handleTokenFromRegistrationSite({
required MatrixState matrix,
required String uri,
}) async {
final token = Uri.parse(uri).queryParameters['loginToken'];
Logs().d(
"ConnectPageMixin: handleTokenFromRegistrationSite: token: $token",
);
if (token == null || token.isEmpty == true) return;
matrix.loginType = LoginType.mLoginToken;
await TwakeDialog.showFutureLoadingDialogFullScreen(
future: () => matrix.getLoginClient().login(
LoginType.mLoginToken,
token: token,
initialDeviceDisplayName: PlatformInfos.clientName,
),
);
try {
final token = Uri.parse(uri).queryParameters['loginToken'];
Logs().d(
"ConnectPageMixin: handleTokenFromRegistrationSite: token: $token",
);
if (token == null || token.isEmpty == true) {
return SsoLoginState.tokenEmpty;
}
matrix.loginType = LoginType.mLoginToken;
await TwakeDialog.showStreamDialogFullScreen(
future: () => matrix
.getLoginClient()
.login(
LoginType.mLoginToken,
token: token,
initialDeviceDisplayName: PlatformInfos.clientName,
)
.timeout(
AutoHomeserverPickerController.autoHomeserverPickerTimeout,
onTimeout: () {
throw CheckHomeserverTimeoutException();
},
),
);
return SsoLoginState.success;
} catch (e) {
Logs()
.e('ConnectPageMixin:: handleTokenFromRegistrationSite(): error: $e');
return SsoLoginState.error;
}
}

void resetLocationPathWithLoginToken({
Expand Down

0 comments on commit b93a184

Please sign in to comment.