tryFetchServerpodCloudAuthData static method

Future<ServerpodCloudAuthData?> tryFetchServerpodCloudAuthData({
  1. required String localStoragePath,
  2. required CommandLogger logger,
})

Implementation

static Future<ServerpodCloudAuthData?> tryFetchServerpodCloudAuthData({
  required final String localStoragePath,
  required final CommandLogger logger,
}) async {
  try {
    final authData = await LocalStorageManager.tryFetchAndDeserializeJsonFile(
      fileName: ResourceManagerConstants.serverpodCloudAuthFilePath,
      localStoragePath: localStoragePath,
      fromJson: ServerpodCloudAuthData.fromJson,
    );
    if (authData != null) {
      return authData;
    }
  } on ReadException catch (_) {
    logger.error(
        'Could not read file ${ResourceManagerConstants.serverpodCloudAuthFilePath}.',
        hint:
            'Please check that the Serverpod Cloud CLI has the correct permissions to '
            'read the file. If the problem persists, try deleting the file.');
    return null;
  } on DeserializationException catch (_) {
    return null;
  }

  // Transparently migrate old local auth data to new file path.
  // TODO: Remove this code when users have had time to run scloud which
  // automatically executes this.
  return await _tryMigrateAuthData(localStoragePath: localStoragePath);
}