From 70e2323f1d25231341072fcff73eea0119f783c3 Mon Sep 17 00:00:00 2001 From: Nikolaus Heger Date: Wed, 17 Dec 2025 12:44:33 +0800 Subject: [PATCH 1/4] Auth time fix make sure auth time defaults to 1 minute, and have one source of truth. Fixes a bug where auth time display was incorrect when first enabling auth. --- .../main/screens/authentication_settings_screen.dart | 7 ++++--- mobile-app/lib/providers/local_auth_provider.dart | 3 +++ mobile-app/lib/services/local_auth_service.dart | 12 +++++++----- quantus_sdk/lib/src/services/settings_service.dart | 2 ++ 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/mobile-app/lib/features/main/screens/authentication_settings_screen.dart b/mobile-app/lib/features/main/screens/authentication_settings_screen.dart index 87fc17ae..5ff36376 100644 --- a/mobile-app/lib/features/main/screens/authentication_settings_screen.dart +++ b/mobile-app/lib/features/main/screens/authentication_settings_screen.dart @@ -38,18 +38,19 @@ class _AuthenticationSettingsScreenState extends State _loadAuthenticationSettings() async { try { final isEnabled = _localAuthService.isLocalAuthEnabled(); - final authTimeout = _localAuthService.getAuthTimeout(); + final authTimeout = _localAuthService.getAuthTimeoutMinutes(); final isAvailable = await _localAuthService.isBiometricAvailable(); final description = await _localAuthService.getBiometricDescription(); @@ -143,7 +144,7 @@ class _AuthenticationSettingsScreenState extends State { } } +// this feels wrong. One bug is it will count from last authenticated time, so if I run the app for 1 minute, then +// go away to another app, then come back immediately, it will require auth. +// TODO: Fix. void lockApp() { if (_localAuthService.shouldRequireAuthentication()) { state = state.copyWith(isAuthenticated: false); diff --git a/mobile-app/lib/services/local_auth_service.dart b/mobile-app/lib/services/local_auth_service.dart index d0a27e72..f924d544 100644 --- a/mobile-app/lib/services/local_auth_service.dart +++ b/mobile-app/lib/services/local_auth_service.dart @@ -55,11 +55,11 @@ class LocalAuthService { _settingsService.setAuthEnabled(enabled); } - int getAuthTimeout() { - return _settingsService.getAuthTimeout() ?? 0; + int getAuthTimeoutMinutes() { + return _settingsService.getAuthTimeout() ?? 1; } - void setAuthTimeout(int timeoutDurationInMinutes) { + void setAuthTimeoutMinutes(int timeoutDurationInMinutes) { return _settingsService.setAuthTimeout(timeoutDurationInMinutes); } @@ -175,9 +175,10 @@ class LocalAuthService { if (!isEnabled) return false; final DateTime? lastAuthTime = _settingsService.getLastSuccessfulAuthTime(); + if (lastAuthTime == null) return true; - final int timeoutDurationInMinutes = _settingsService.getAuthTimeout() ?? 5; + final int timeoutDurationInMinutes = getAuthTimeoutMinutes(); final Duration authTimeout = Duration(minutes: timeoutDurationInMinutes); @@ -186,7 +187,8 @@ class LocalAuthService { 'auth time difference: ${DateTime.now().difference(lastAuthTime).inSeconds}', ); - return DateTime.now().difference(lastAuthTime) > authTimeout; + final isTimeout = DateTime.now().difference(lastAuthTime) > authTimeout; + return isTimeout; } catch (e) { debugPrint('Error checking if authentication is required: $e'); return true; // Err on the side of caution diff --git a/quantus_sdk/lib/src/services/settings_service.dart b/quantus_sdk/lib/src/services/settings_service.dart index c35685a4..5a103c11 100644 --- a/quantus_sdk/lib/src/services/settings_service.dart +++ b/quantus_sdk/lib/src/services/settings_service.dart @@ -225,6 +225,7 @@ class SettingsService { _prefs.setString(_lastSuccessfulAuthKey, time.toIso8601String()); } + // Do not call this directly - call local auth service getAuthTimeoutMinutes() instead. int? getAuthTimeout() { final int? authTimeout = _prefs.getInt(_authTimeoutKey); if (authTimeout == null) return null; @@ -232,6 +233,7 @@ class SettingsService { return authTimeout; } + // Do not call this directly - call local auth service setAuthTimeoutMinutes() instead. void setAuthTimeout(int timeoutDurationInMinutes) { _prefs.setInt(_authTimeoutKey, timeoutDurationInMinutes); } From f6b2d8f13795ca91357932b8262112d2372d6ec5 Mon Sep 17 00:00:00 2001 From: Nikolaus Heger Date: Wed, 17 Dec 2025 13:13:13 +0800 Subject: [PATCH 2/4] format --- mobile-app/lib/providers/local_auth_provider.dart | 6 +++--- mobile-app/lib/services/local_auth_service.dart | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mobile-app/lib/providers/local_auth_provider.dart b/mobile-app/lib/providers/local_auth_provider.dart index cc79fb8b..6ba54d61 100644 --- a/mobile-app/lib/providers/local_auth_provider.dart +++ b/mobile-app/lib/providers/local_auth_provider.dart @@ -49,9 +49,9 @@ class LocalAuthController extends StateNotifier { } } -// this feels wrong. One bug is it will count from last authenticated time, so if I run the app for 1 minute, then -// go away to another app, then come back immediately, it will require auth. -// TODO: Fix. + // this feels wrong. One bug is it will count from last authenticated time, so if I run the app for 1 minute, then + // go away to another app, then come back immediately, it will require auth. + // TODO: Fix. void lockApp() { if (_localAuthService.shouldRequireAuthentication()) { state = state.copyWith(isAuthenticated: false); diff --git a/mobile-app/lib/services/local_auth_service.dart b/mobile-app/lib/services/local_auth_service.dart index f924d544..a00b081f 100644 --- a/mobile-app/lib/services/local_auth_service.dart +++ b/mobile-app/lib/services/local_auth_service.dart @@ -175,7 +175,7 @@ class LocalAuthService { if (!isEnabled) return false; final DateTime? lastAuthTime = _settingsService.getLastSuccessfulAuthTime(); - + if (lastAuthTime == null) return true; final int timeoutDurationInMinutes = getAuthTimeoutMinutes(); @@ -187,7 +187,7 @@ class LocalAuthService { 'auth time difference: ${DateTime.now().difference(lastAuthTime).inSeconds}', ); - final isTimeout = DateTime.now().difference(lastAuthTime) > authTimeout; + final isTimeout = DateTime.now().difference(lastAuthTime) > authTimeout; return isTimeout; } catch (e) { debugPrint('Error checking if authentication is required: $e'); From a3de6e6ca15763883ea52f6b17187e5dafb31c20 Mon Sep 17 00:00:00 2001 From: Nikolaus Heger Date: Wed, 17 Dec 2025 13:16:57 +0800 Subject: [PATCH 3/4] remove comments --- mobile-app/lib/providers/local_auth_provider.dart | 3 --- 1 file changed, 3 deletions(-) diff --git a/mobile-app/lib/providers/local_auth_provider.dart b/mobile-app/lib/providers/local_auth_provider.dart index 6ba54d61..f83cba67 100644 --- a/mobile-app/lib/providers/local_auth_provider.dart +++ b/mobile-app/lib/providers/local_auth_provider.dart @@ -49,9 +49,6 @@ class LocalAuthController extends StateNotifier { } } - // this feels wrong. One bug is it will count from last authenticated time, so if I run the app for 1 minute, then - // go away to another app, then come back immediately, it will require auth. - // TODO: Fix. void lockApp() { if (_localAuthService.shouldRequireAuthentication()) { state = state.copyWith(isAuthenticated: false); From 1b54916d0b1267a94f5cd6890e1c0add2e94a362 Mon Sep 17 00:00:00 2001 From: Nikolaus Heger Date: Wed, 17 Dec 2025 13:17:43 +0800 Subject: [PATCH 4/4] doc comments --- quantus_sdk/lib/src/services/settings_service.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/quantus_sdk/lib/src/services/settings_service.dart b/quantus_sdk/lib/src/services/settings_service.dart index 5a103c11..98c5c1f4 100644 --- a/quantus_sdk/lib/src/services/settings_service.dart +++ b/quantus_sdk/lib/src/services/settings_service.dart @@ -225,7 +225,7 @@ class SettingsService { _prefs.setString(_lastSuccessfulAuthKey, time.toIso8601String()); } - // Do not call this directly - call local auth service getAuthTimeoutMinutes() instead. + /// Do not call this directly - call local auth service getAuthTimeoutMinutes() instead. int? getAuthTimeout() { final int? authTimeout = _prefs.getInt(_authTimeoutKey); if (authTimeout == null) return null; @@ -233,7 +233,7 @@ class SettingsService { return authTimeout; } - // Do not call this directly - call local auth service setAuthTimeoutMinutes() instead. + /// Do not call this directly - call local auth service setAuthTimeoutMinutes() instead. void setAuthTimeout(int timeoutDurationInMinutes) { _prefs.setInt(_authTimeoutKey, timeoutDurationInMinutes); }