Skip to content

Commit

Permalink
[login_service] migrate biometricAuthState to new version
Browse files Browse the repository at this point in the history
  • Loading branch information
clangenb committed Jul 15, 2023
1 parent f5c950a commit 08c9b27
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions app/lib/modules/login/service/login_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,23 @@ final class LoginService {
BiometricAuthState? get getBiometricAuthState {
final biometricAuthState = preferences.getString(biometricAuthStateKey);
if (biometricAuthState != null) return BiometricAuthState.fromString(biometricAuthState);
final biometricAuthenticationEnabled = preferences.getBool(oldBiometricAuthStateKey);
return switch (biometricAuthenticationEnabled) {

// See if we had set a state in earlier app versions
final biometricAuthenticationEnabledOld = preferences.getBool(oldBiometricAuthStateKey);
if (biometricAuthenticationEnabledOld == null) return null;

// migrate old storage to new one and return state
final biometricAuthStateOld = switch (biometricAuthenticationEnabledOld) {
true => BiometricAuthState.enabled,
false => BiometricAuthState.disabled,
_ => null,
};

// migrate the old storage to the new one
setBiometricAuthState(biometricAuthStateOld);
// clear the old storage
preferences.remove(oldBiometricAuthStateKey);

return biometricAuthStateOld;
}

Future<void> setBiometricAuthState(BiometricAuthState biometricAuthState) async {
Expand Down

0 comments on commit 08c9b27

Please sign in to comment.