From 9c0aea66ec7400a522f7acd8c4bf8363907ed1db Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Mon, 4 Sep 2023 16:45:08 +0530 Subject: [PATCH] Check for existing key before creating new --- lib/core/configuration.dart | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/core/configuration.dart b/lib/core/configuration.dart index e2701765e5..a39052e655 100644 --- a/lib/core/configuration.dart +++ b/lib/core/configuration.dart @@ -438,12 +438,22 @@ class Configuration { } Future optForOfflineMode() async { - _offlineAuthKey = Sodium.bin2base64(CryptoUtil.generateKey()); - await _secureStorage.write( + if ((await _secureStorage.containsKey( key: offlineAuthSecretKey, - value: _offlineAuthKey, iOptions: _secureStorageOptionsIOS, - ); + ))) { + _offlineAuthKey = await _secureStorage.read( + key: offlineAuthSecretKey, + iOptions: _secureStorageOptionsIOS, + ); + } else { + _offlineAuthKey = Sodium.bin2base64(CryptoUtil.generateKey()); + await _secureStorage.write( + key: offlineAuthSecretKey, + value: _offlineAuthKey, + iOptions: _secureStorageOptionsIOS, + ); + } await _preferences.setBool(hasOptedForOfflineModeKey, true); }