verifyClientId method

Future<RequestResponse<String?>> verifyClientId(
  1. String? id
)

Verify the client ID from the backend.

In case the client id is valid, it's returned within RequestResponse.

Implementation

Future<RequestResponse<String?>> verifyClientId(String? id) async {
  if (id != null) {
    final r = await fetchId();
    if (!r.isSuccess) {
      config.logger.e(<String>[
        'Renovation Core: Failed to update clientId from renovation_bench',
        'Proceeding with the id from localStorage: $id'
      ]);
      return RequestResponse.success<String>('Using local clientID $id');
    } else if (r.data != id) {
      config.logger.e(<String>[
        'Renovation Core: localStorage and server clientId mismatch',
        'Reinitializing with clientId: ' + id
      ]);
    }
    Request.setClientId(r.data);
    await config.coreInstance.init(config.hostUrl, clientId: r.data);
  } else {
    final fetchedID = await fetchId();
    if (fetchedID.isSuccess) {
      Request.setClientId(fetchedID.data);
    } else {
      config.logger.e('Renovation Core: Failed fetching client id');
    }
    return RequestResponse.success<String?>(fetchedID.data);
  }
  return RequestResponse.fail<String>(handleError(
      'verifyClientId',
      ErrorDetail(
          info: Information(
              cause: 'Client ID not defined',
              suggestion: 'Please define client id',
              httpCode: 400,
              data: 'Please define client id'))));
}