title: AWS Cognito Identity JS: Forget/Remember/Do Not Remember Device
body: <p>I'm working with the AWS Cognito Identity JS SDK (<a href="https://github.com/aws/amazon-cognito-identity-js" rel="nofollow noreferrer">https://github.com/aws/amazon-cognito-identity-js</a>) and I'm trying to set up a few buttons to test the <code>setDeviceStatusRemembered</code>, <code>setDeviceStatusNotRemembered</code>, and <code>forgetDevice</code> functionality but I keep getting an error saying:</p>
  
  <p><code>MissingRequiredParameter: Missing required key 'DeviceKey' in params</code></p>
  
  <p>Here is an implementation of one of the functions:</p>
  
  <pre><code>forgetDevice = function(){
  
  var cognitoUser = userPool.getCurrentUser();
  
  if (cognitoUser != null) {
      cognitoUser.getSession(function(err, session) {
          if (err) {
              alert(err);
              signOut();
              return;
          }
  
          console.log('session validity: ' + session.isValid());
  
          cognitoUser.forgetDevice({
              onSuccess: function (result) {
                  console.log('call result: ' + result);
              },
              onFailure: function(err) {
                  alert(err);
              }
          });
      });
    } 
  }
  </code></pre>
  
  <p>If I  change up the function like this:</p>
  
  <pre><code>forgetDevice = function(cognitoUser){
      cognitoUser.forgetDevice({
          onSuccess: function (result) {
              console.log('call result: ' + result);
          },
          onFailure: function(err) {
              alert(err);
          }
      });
  }
  </code></pre>
  
  <p>and I call the function from the <code>cognitoUser.authenticateUser</code> <code>success</code> callback function, passing <code>cognitoUser</code> as argument into the <code>forgetDevice</code> function above everything works perfectly.</p>
  
  <p>From looking at the <code>session</code> object in the first implementation it appears that the <code>session</code> object does not contain the <code>DeviceKey</code> property so the <code>cognitoUser.forgetDevice()</code> call fails.</p>
  
  <p>What I'm trying to figure out is, should I just be calling the  <code>setDeviceStatusRemembered</code>, <code>setDeviceStatusNotRemembered</code>, and <code>forgetDevice</code> functions on login, or should I be able to call them any time within my application? Hopefully that makes sense. Any help would be greatly appreciated. Thanks!</p>