execute method

Future<AuthResponse> execute(
  1. String appPackageName,
  2. String authCode,
  3. String deviceId,
  4. String email,
)

Implementation

Future<AuthResponse> execute(String appPackageName, String authCode, String deviceId, String email) async {
  if (authCode.isEmpty) {
    return ErrorResponse(400, "Invalid code", "Please enter a code");
  }

  var authResponse = await _remoteStorageDatasource.getRefreshTokenFromApi(appPackageName, authCode, deviceId, email);
  switch (authResponse) {
    case ErrorResponse():
      break;

    case SuccessResponse():
      debugPrint("Body: ${authResponse.body}");
      try {
        TokenModel tokenModel = TokenModel.fromJson(
            json.decode(authResponse.body));
        if (tokenModel.expressToken?.refreshToken != null) {
          _preferencesDatasource.saveRefreshToken(
              tokenModel.expressToken?.refreshToken ?? "");
        }
        SessionModel sessionModel = SessionModel.fromJson(
            json.decode(authResponse.body));
        _preferencesDatasource.saveSession(jsonEncode(sessionModel.toJson()));
      } catch (e) {
        debugPrint("RequestRefreshTokenUseCase: Token Model exception: ${e}");
      }

      break;
  }

  return authResponse;
}