tryTokenAutoAuthenticate method

Future tryTokenAutoAuthenticate()

Implementation

Future tryTokenAutoAuthenticate() async {
  try {
    String apiUrl = ApiConstantDev.urlApiAutoAuthenticate;
    String packageName = TypeSafeConversion.nullSafeString( apiClient.packageInfo?.packageName);
    logCat('tryTokenAutoAuthenticate() | packageName:$packageName ');
    //region attributs
    Map<String, String> param = <String, String>{};
    param[UsersProperty.packageName.columnName] = packageName;//Constant.packageChantChoraleEtGroupe;
    //endregion
    var response = await apiClient.postData(apiUrl: apiUrl, data: param, fName: 'tryTokenAutoAuthenticate');
    if (response.statusCode == HttpStatus.ok) {
      var data = jsonDecode(response.body);
      var bearerToken = data['jwtToken'];
      apiClient.bearerToken = bearerToken;
      apiClient.setApiToken(bearerToken);
      logCat('tryTokenAutoAuthenticate() | packageName:$packageName | response.body: $data');
      return data['jwtToken'];
    } else {
      tentative++;
      if (tentative <= 3) {
        await tryTokenAutoAuthenticate();
      }
    }
  } catch (ex, trace) {
    logError(ex, trace: trace, position: 'refreshDeviceToken');
  }
  return null;
}