Nicer verification error

This commit is contained in:
Henry Hiles 2026-01-25 15:00:33 +00:00
commit 5424dda62a
No known key found for this signature in database
2 changed files with 45 additions and 9 deletions

View file

@ -82,7 +82,7 @@ class ClientController extends AsyncNotifier<int> {
try { try {
await sendCommand("verify", {"recovery_key": recoveryKey}); await sendCommand("verify", {"recovery_key": recoveryKey});
return true; return true;
} catch (_) { } catch (error) {
return false; return false;
} }
} }
@ -91,7 +91,7 @@ class ClientController extends AsyncNotifier<int> {
try { try {
await sendCommand("login", login.toJson()); await sendCommand("login", login.toJson());
return true; return true;
} catch (_) { } catch (error) {
return false; return false;
} }
} }
@ -102,7 +102,7 @@ class ClientController extends AsyncNotifier<int> {
"user_id": "@fakeuser:${homeserver.host}", "user_id": "@fakeuser:${homeserver.host}",
}); });
return (response["m.homeserver"] as Map<String, dynamic>)["base_url"]; return (response["m.homeserver"] as Map<String, dynamic>)["base_url"];
} catch (_) { } catch (error) {
return null; return null;
} }
} }

View file

@ -10,6 +10,7 @@ class VerifyPage extends HookConsumerWidget {
@override @override
Widget build(BuildContext context, WidgetRef ref) { Widget build(BuildContext context, WidgetRef ref) {
final passphraseController = useTextEditingController(); final passphraseController = useTextEditingController();
final isVerifying = useState(false);
return AlertDialog( return AlertDialog(
title: Text("Verify"), title: Text("Verify"),
content: Column( content: Column(
@ -32,11 +33,46 @@ class VerifyPage extends HookConsumerWidget {
), ),
actions: [ actions: [
TextButton( TextButton(
onPressed: () async { onPressed: isVerifying.value
ref ? null
: () async {
final scaffoldMessenger = ScaffoldMessenger.of(context);
final snackbar = scaffoldMessenger.showSnackBar(
SnackBar(
content: Text(
"Attempting to verify with recovery key...",
),
duration: Duration(days: 999),
),
);
isVerifying.value = true;
final success = await ref
.watch(ClientController.provider.notifier) .watch(ClientController.provider.notifier)
.verify(passphraseController.text); .verify(passphraseController.text);
Navigator.of(context).pop();
snackbar.close();
if (!success) {
isVerifying.value = false;
if (context.mounted) {
scaffoldMessenger.showSnackBar(
SnackBar(
backgroundColor: Theme.of(
context,
).colorScheme.errorContainer,
content: Text(
"Verification failed. Is your passphrase correct?",
style: TextStyle(
color: Theme.of(
context,
).colorScheme.onErrorContainer,
),
),
),
);
}
}
}, },
child: Text("Verify"), child: Text("Verify"),
), ),