AWS Cognito Identity JS: Forget/Remember/Do Not Remember Device

∥☆過路亽.° 提交于 2019-12-12 05:19:03

问题


I'm working with the AWS Cognito Identity JS SDK (https://github.com/aws/amazon-cognito-identity-js) and I'm trying to set up a few buttons to test the setDeviceStatusRemembered, setDeviceStatusNotRemembered, and forgetDevice functionality but I keep getting an error saying:

MissingRequiredParameter: Missing required key 'DeviceKey' in params

Here is an implementation of one of the functions:

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);
            }
        });
    });
  } 
}

If I change up the function like this:

forgetDevice = function(cognitoUser){
    cognitoUser.forgetDevice({
        onSuccess: function (result) {
            console.log('call result: ' + result);
        },
        onFailure: function(err) {
            alert(err);
        }
    });
}

and I call the function from the cognitoUser.authenticateUser success callback function, passing cognitoUser as argument into the forgetDevice function above everything works perfectly.

From looking at the session object in the first implementation it appears that the session object does not contain the DeviceKey property so the cognitoUser.forgetDevice() call fails.

What I'm trying to figure out is, should I just be calling the setDeviceStatusRemembered, setDeviceStatusNotRemembered, and forgetDevice 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!


回答1:


Does this help:

Note that if device tracking is enabled for the user pool with a setting that user opt-in is required, you need to implement an onSuccess(result, userConfirmationNecessary) callback, collect user input and call either setDeviceStatusRemembered to remember the device or setDeviceStatusNotRemembered to not remember the device.

http://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-user-pools-device-tracking.html

Also can you attempt calling getCachedDeviceKeyAndPassword to populate the deviceKey in the CognitoUser object?



来源:https://stackoverflow.com/questions/44792164/aws-cognito-identity-js-forget-remember-do-not-remember-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!