diff --git a/lib/services/auth_service.dart b/lib/services/auth_service.dart index bb9e645..c7c8d75 100644 --- a/lib/services/auth_service.dart +++ b/lib/services/auth_service.dart @@ -34,7 +34,8 @@ class AccountsService extends ChangeNotifier { final lastActiveProfile = await _getStoredLoginState(); final result = await runCatchingAsync(() async { - for (final p in secretsService.profiles) { + final initialProfiles = secretsService.profiles; + for (final p in initialProfiles) { if (!p.loggedIn) { _loggedOutProfiles.add(p); continue; @@ -50,7 +51,7 @@ class AccountsService extends ChangeNotifier { } if (_currentProfile == null && _loggedInProfiles.isNotEmpty) { - setActiveProfile(_loggedInProfiles.first); + await setActiveProfile(_loggedInProfiles.first); } return Result.ok(loggedIn); @@ -79,11 +80,12 @@ class AccountsService extends ChangeNotifier { ); if (_loggedInProfiles.isEmpty) { - setActiveProfile(loginProfile, withNotification: withNotification); + await setActiveProfile(loginProfile, + withNotification: withNotification); } _loggedInProfiles.add(loginProfile); _loggedOutProfiles.remove(loginProfile); - secretsService.addOrUpdateProfile(loginProfile); + await secretsService.addOrUpdateProfile(loginProfile); if (withNotification) { notifyListeners(); } @@ -99,11 +101,11 @@ class AccountsService extends ChangeNotifier { Future signOut(Profile profile, {bool withNotification = true}) async { if (_currentProfile == profile) { - clearActiveProfile(withNotification: withNotification); + await clearActiveProfile(withNotification: withNotification); } _loggedInProfiles.remove(profile); _loggedOutProfiles.add(profile.copyWithLoginUpdate(false)); - secretsService.addOrUpdateProfile(profile.copyWithLoginUpdate(false)); + await secretsService.addOrUpdateProfile(profile.copyWithLoginUpdate(false)); if (_loggedInProfiles.isNotEmpty) { setActiveProfile( diff --git a/lib/services/secrets_service.dart b/lib/services/secrets_service.dart index 8908599..5abf836 100644 --- a/lib/services/secrets_service.dart +++ b/lib/services/secrets_service.dart @@ -15,7 +15,8 @@ class SecretsService { final _cachedProfiles = {}; - List get profiles => UnmodifiableListView(_cachedProfiles); + List get profiles => + UnmodifiableListView(List.from(_cachedProfiles)); final _secureStorage = const FlutterSecureStorage( iOptions: IOSOptions(