AWS Cognito - Offline Data Availability

I am creating a phonegap app and using AWS Cognito to store user data. Cognito's description says the data is available offline. This doesn't work in my code:

var add_data;    
function getCognitoData(){
 var params = {
  IdentityPoolId: COGNITO_IDENTITY_POOL_ID,
  Logins: {
   'graph.facebook.com': FACEBOOK_TOKEN
  }  
 };
 AWS.config.region = AWS_REGION;
 AWS.config.credentials = new AWS.CognitoIdentityCredentials(params);
 AWS.config.credentials.get(function(err) {
  if (err) {
   console.log("Error: "+err);
   return;
  }
  console.log("Cognito Identity Id: " + AWS.config.credentials.identityId);

  var syncClient = new AWS.CognitoSyncManager();

  syncClient.openOrCreateDataset('myDataset', function(err, dataset) {
   dataset.get('myKey', function(err, value) {
    console.log(value, err);
   });

   add_data = function(thisid, thisval) {
    dataset.put(thisid, thisval, function(err, record){
     dataset.synchronize({
      onSuccess: function(data, newRecords) {
       console.log("success", newRecords);
      },
      onFailure: function(err) {
       console.log("error", err);
      },
      onConflict: function(dataset, conflicts, callback) {
       console.log("sync conflict", dataset, conflicts);
       var resolved = [];

       for (var i=0; i<conflicts.length; i++) {
        resolved.push(conflicts[i].resolveWithRemoteRecord());
       }

       dataset.resolve(resolved, function() {
        return callback(true);
       });
      }
     });
    });
   }
  });
 });
}

      

The AWS credentials for the identity pool and Facebook token are already set up and working online, but I am not getting the dataset data when I am offline.

Am I doing something wrong, or is it not possible at all to get the Cognito dataset data while offline? I read that the data is actually stored in local storage.

I am using the current AWS SKD (Release v2.1.42) and Amazon Cognito JS.

+3


source to share


2 answers


You can turn off data. You need to sync the dataset to get the content that might be inside, otherwise it is expected to be empty. You do it? If not, try doing this, but if so, can you update your code above?



0


source


There was an error with aws-sdk-js

which caused the error offline. CognitoSync depends on aws-sdk-js

. Should work now with aws-sdk-js@2.7.21

. Make sure you update.



0


source







All Articles