Skip to content

Commit

Permalink
TW-1711: Handle deep link from registration
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhhdev committed Apr 26, 2024
1 parent 2cdf44c commit a24c82b
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions lib/pages/login/on_auth_redirect.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/utils/dialog/twake_dialog.dart';
import 'package:fluffychat/utils/platform_infos.dart';
import 'package:fluffychat/widgets/matrix.dart';
Expand Down Expand Up @@ -33,16 +34,34 @@ class _OnAuthRedirectState extends State<OnAuthRedirect> {
return queryParams[key];
}

static bool get homeserverIsConfigured =>
AppConfig.homeserver != 'https://example.com/' ||
AppConfig.homeserver.isNotEmpty;

Future<void> tryLoggingUsingToken() async {
try {
final isConfigured = await AppConfig.initConfigCompleter.future;
if (!isConfigured) {
if (!AppConfig.hasReachedMaxRetries) {
tryLoggingUsingToken();
} else {
Logs().e(
'OnAuthRedirect::tryGetHomeserver(): Config not found',
);
TwakeApp.router.go('/home', extra: true);
}
}
final homeserver = AppConfig.homeserver;
if (!homeserverIsConfigured) {
throw Exception(
'tryLoggingUsingToken(): Missing homeserver',
);
}

final loginToken = getQueryParameter('loginToken');
final homeserver = getQueryParameter('homeserver');
if (loginToken == null ||
loginToken.isEmpty ||
homeserver == null ||
homeserver.isEmpty) {
if (loginToken == null || loginToken.isEmpty) {
throw Exception(
'tryLoggingUsingToken(): Missing loginToken or homeserver',
'tryLoggingUsingToken(): Missing loginToken',
);
}
Logs().i('tryLoggingUsingToken::loginToken: $loginToken');
Expand Down

0 comments on commit a24c82b

Please sign in to comment.