mountCredentials method Null safety

Future<void> mountCredentials()

Mounts already stored credentials, called at app startup

Implementation

static Future<void> mountCredentials() async {
  String? userId;
  String? password;

  try {
    userId = await DaoSecuredString.get(_USER_ID);
    password = await DaoSecuredString.get(_PASSWORD);
  } on PlatformException {
    /// Decrypting the values can go wrong if, for example, the app was
    /// manually overwritten from an external apk.
    DaoSecuredString.remove(key: _USER_ID);
    DaoSecuredString.remove(key: _PASSWORD);
    debugPrint('Credentials query failed, you have been logged out');
  }

  if (userId == null || password == null) {
    return;
  }

  final User user = User(userId: userId, password: password);
  OpenFoodAPIConfiguration.globalUser = user;
}