mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-11-22 16:32:01 +03:00
Customize error messages for connection failures.
This commit is contained in:
parent
8674015f34
commit
f33087fd0f
@ -1,18 +1,46 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:yubico_authenticator/desktop/models.dart';
|
||||
|
||||
class AppFailureScreen extends StatelessWidget {
|
||||
final String reason;
|
||||
final Object reason;
|
||||
const AppFailureScreen(this.reason, {super.key}) : super();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cause = reason;
|
||||
if (cause is RpcError) {
|
||||
if (cause.status == 'connection-error' &&
|
||||
cause.body['connection'] == 'ccid') {
|
||||
var msg = 'Failed to open smart card connection';
|
||||
if (Platform.isMacOS) {
|
||||
msg += '\nTry to remove and re-insert your YubiKey to regain access.';
|
||||
} else if (Platform.isLinux) {
|
||||
msg += '\nMake sure pcscd is running.';
|
||||
}
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
msg,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
reason,
|
||||
cause.toString(),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
|
@ -10,6 +10,7 @@ import '../../app/views/app_loading_screen.dart';
|
||||
import '../../app/views/app_page.dart';
|
||||
import '../../app/views/graphics.dart';
|
||||
import '../../app/views/message_page.dart';
|
||||
import '../../desktop/models.dart';
|
||||
import '../../desktop/state.dart';
|
||||
import '../../management/models.dart';
|
||||
import '../../theme.dart';
|
||||
@ -52,9 +53,10 @@ class FidoScreen extends ConsumerWidget {
|
||||
'WebAuthn requires the FIDO2 application to be enabled on your YubiKey',
|
||||
);
|
||||
}
|
||||
if (Platform.isWindows) {
|
||||
if (!ref
|
||||
.watch(rpcStateProvider.select((state) => state.isAdmin))) {
|
||||
if (Platform.isWindows && error is RpcError) {
|
||||
if (error.status == 'connection-error' &&
|
||||
!ref.watch(
|
||||
rpcStateProvider.select((state) => state.isAdmin))) {
|
||||
return MessagePage(
|
||||
title: const Text('WebAuthn'),
|
||||
graphic: noPermission,
|
||||
@ -85,7 +87,7 @@ class FidoScreen extends ConsumerWidget {
|
||||
return AppPage(
|
||||
title: const Text('WebAuthn'),
|
||||
centered: true,
|
||||
child: AppFailureScreen('$error'),
|
||||
child: AppFailureScreen(error),
|
||||
);
|
||||
},
|
||||
data: (fidoState) {
|
||||
|
@ -241,7 +241,7 @@ class _ManagementScreenState extends ConsumerState<ManagementScreen> {
|
||||
final child =
|
||||
ref.watch(managementStateProvider(widget.deviceData.node.path)).when(
|
||||
loading: () => const AppLoadingScreen(),
|
||||
error: (error, _) => AppFailureScreen('$error'),
|
||||
error: (error, _) => AppFailureScreen(error),
|
||||
data: (info) {
|
||||
bool hasConfig = info.version.major > 4;
|
||||
if (hasConfig) {
|
||||
|
@ -34,7 +34,7 @@ class OathScreen extends ConsumerWidget {
|
||||
error: (error, _) => AppPage(
|
||||
title: const Text('Authenticator'),
|
||||
centered: true,
|
||||
child: AppFailureScreen('$error'),
|
||||
child: AppFailureScreen(error),
|
||||
),
|
||||
data: (oathState) => oathState.locked
|
||||
? _LockedView(devicePath, oathState)
|
||||
|
Loading…
Reference in New Issue
Block a user