diff --git a/lib/src/utils/solid_file_operations_download.dart b/lib/src/utils/solid_file_operations_download.dart index 08f23164..84739188 100644 --- a/lib/src/utils/solid_file_operations_download.dart +++ b/lib/src/utils/solid_file_operations_download.dart @@ -165,10 +165,12 @@ class SolidFileDownloadOperations { if (!context.mounted) return; - await getKeyFromUserIfRequired( + if (!await getKeyFromUserIfRequired( context, const Text('Please enter your security key to download the file'), - ); + )) { + return; + } if (!context.mounted) return; @@ -308,10 +310,12 @@ class SolidFileDownloadOperations { // Get security key if required. - await getKeyFromUserIfRequired( + if (!await getKeyFromUserIfRequired( context, const Text('Please enter your security key to download the files'), - ); + )) { + return; + } if (!context.mounted) return; diff --git a/lib/src/utils/solid_file_operations_print.dart b/lib/src/utils/solid_file_operations_print.dart index 3e12511b..f0810100 100644 --- a/lib/src/utils/solid_file_operations_print.dart +++ b/lib/src/utils/solid_file_operations_print.dart @@ -419,10 +419,12 @@ class SolidFilePrintOperations { try { if (!context.mounted) return; - await getKeyFromUserIfRequired( + if (!await getKeyFromUserIfRequired( context, const Text('Please enter your security key to print the file'), - ); + )) { + return; + } if (!context.mounted) return; diff --git a/lib/src/utils/solid_file_operations_upload.dart b/lib/src/utils/solid_file_operations_upload.dart index dbbfce53..e6a7a0d3 100644 --- a/lib/src/utils/solid_file_operations_upload.dart +++ b/lib/src/utils/solid_file_operations_upload.dart @@ -107,10 +107,12 @@ class SolidFileUploadOperations { // Ensure the security key is available before writing encrypted data. - await getKeyFromUserIfRequired( + if (!await getKeyFromUserIfRequired( context, const Text('Please enter your security key to upload the file'), - ); + )) { + return; + } if (!context.mounted) return; diff --git a/lib/src/utils/solid_pod_helpers.dart b/lib/src/utils/solid_pod_helpers.dart index 5303eec4..33da4b6a 100644 --- a/lib/src/utils/solid_pod_helpers.dart +++ b/lib/src/utils/solid_pod_helpers.dart @@ -113,12 +113,12 @@ Future loginIfRequired(BuildContext context) async { /// Ask for the security key from the user if the security key is not available /// or cannot be verfied using the verification key stored in PODs. -Future getKeyFromUserIfRequired( +Future getKeyFromUserIfRequired( BuildContext context, Widget child, ) async { if (await KeyManager.hasSecurityKey()) { - return; + return true; } else { final verificationKey = await KeyManager.getVerificationKey(); // Get the webId to display in the security key prompt. @@ -148,13 +148,13 @@ Future getKeyFromUserIfRequired( submitFunc: (formDataMap) async { await KeyManager.setSecurityKey(formDataMap[inputKey].toString()); debugPrint('Security key saved'); - if (context.mounted) Navigator.pop(context); + if (context.mounted) Navigator.pop(context, true); }, child: child, ); if (context.mounted) { - await Navigator.push( + final result = await Navigator.push( context, MaterialPageRoute(builder: (context) => securityKeyInput), ); @@ -163,6 +163,9 @@ Future getKeyFromUserIfRequired( // changed after the user submitted (or dismissed) the key prompt. await securityKeyNotifier.refreshStatus(); + + return result ?? false; } + return false; } } diff --git a/lib/src/widgets/security_key_ui.dart b/lib/src/widgets/security_key_ui.dart index ff6a0ff9..5a36407c 100644 --- a/lib/src/widgets/security_key_ui.dart +++ b/lib/src/widgets/security_key_ui.dart @@ -246,13 +246,7 @@ class _SecurityKeyUIState extends State { child: SecurityKeyButtons( canSubmit: _canSubmit, onSubmit: () async => _submit(context), - onCancel: () { - if (widget.displayMode == SecurityKeyDisplayMode.dialog) { - Navigator.pop(context); - } else { - pushReplacement(context, widget.child); - } - }, + onCancel: () => Navigator.pop(context, false), ), ), ], diff --git a/lib/src/widgets/solid_login_actions.dart b/lib/src/widgets/solid_login_actions.dart index a70acd99..642ffb70 100644 --- a/lib/src/widgets/solid_login_actions.dart +++ b/lib/src/widgets/solid_login_actions.dart @@ -224,7 +224,7 @@ class SolidLoginActions { // Ensure the security key has been fetched once logged in. if (isLoggedIn) { - await getKeyFromUserIfRequired(context, childWidget); + if (!await getKeyFromUserIfRequired(context, childWidget)) return; if (!context.mounted) return; } diff --git a/lib/src/widgets/solid_login_auth_handler.dart b/lib/src/widgets/solid_login_auth_handler.dart index 11e7c208..7c27176b 100644 --- a/lib/src/widgets/solid_login_auth_handler.dart +++ b/lib/src/widgets/solid_login_auth_handler.dart @@ -232,7 +232,7 @@ class SolidLoginAuthHandler { } if (!context.mounted) return false; - await getKeyFromUserIfRequired(context, childWidget); + if (!await getKeyFromUserIfRequired(context, childWidget)) return false; if (!context.mounted) return true; await pushReplacement(context, childWidget); } @@ -481,7 +481,7 @@ class SolidLoginAuthHandler { } if (!context.mounted) return false; - await getKeyFromUserIfRequired(context, childWidget); + if (!await getKeyFromUserIfRequired(context, childWidget)) return false; if (!context.mounted) return true; await pushReplacement(context, childWidget); }