Hi everyone,
I tried to follow this link and remember user's devices at the login time, however, I always get this error:
1 validation error detected: Value null at 'deviceKey' failed to satisfy constraint: Member must not be null
This is my code:
cognitoUser.setDeviceStatusRemembered({
onSuccess: function (result) {
console.log('call result: ' + result);
},
onFailure: function(err) {
alert(err);
}
});
Is this a bug or I'm missing something?
Hi @saaniaki, thanks for submitting feedback.
Seems that user does not have a deviceKey associated with their user object.
Have you tried calling getCachedDeviceKeyAndPassword to populate the deviceKey for the user?
https://github.com/aws-amplify/amplify-js/blob/master/packages/amazon-cognito-identity-js/src/CognitoUser.js#L1255
Here is a related Stack Overflow question:
https://stackoverflow.com/questions/44792164/aws-cognito-identity-js-forget-remember-do-not-remember-device]
I'm using Angular, the problem was that the type mapping file doesn't have this method in it, so I VSCode couldn't find it. Anyway, I forced it to call it and ignored the typescript error by adding [x: string]: any; to the index.d.ts file for CognitoUser class (not a good idea). Now it's working, thank you!
Hope they add it in the next update!
Device remembering only works in Mobile devices? or can be used for desktops? I tried using sample backend NodeJS code to sign in using Amplify it didn't remember the user.
@saaniaki, this sounds like a feature request to add typescript support to amazon-cognito-identity-js yea?
@koladilip could you post the sample code?
@jordanranz I would say a request to complete the typescript support since they already have it, or to say, complete the typings in https://github.com/aws-amplify/amplify-js/blob/master/packages/amazon-cognito-identity-js/index.d.ts
I got this error today, for my own personal account in my WebApp in production. We do not have mobile app, there is nothing to remember.
I could swear I had login to my app as super admin successfuly, logged out, and at attempt to login again got this error message
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
There's any update on that? I'm facing the same problem
@luizfilipe I am facing the same issue. I cleared the local storage, logged correctly and still returns
1 validation error detected: Value null at 'deviceKey' failed to satisfy constraint: Member must not be null
You have to populate the device key by calling
cognitoUser.getCachedDeviceKeyAndPassword()
The name of the method is misleading. It doesn't "get" or return anything. It just pulls the device key from local storage into js.
getCachedDeviceKeyAndPassword() {
const keyPrefix = `CognitoIdentityServiceProvider.${this.pool.getClientId()}.${
this.username
}`;
const deviceKeyKey = `${keyPrefix}.deviceKey`;
const randomPasswordKey = `${keyPrefix}.randomPasswordKey`;
const deviceGroupKeyKey = `${keyPrefix}.deviceGroupKey`;
if (this.storage.getItem(deviceKeyKey)) {
this.deviceKey = this.storage.getItem(deviceKeyKey);
this.randomPassword = this.storage.getItem(randomPasswordKey);
this.deviceGroupKey = this.storage.getItem(deviceGroupKeyKey);
}
}
Could we mark getCachedDeviceKeyAndPassword()as a public method of the CognitoUser class? This would help greatly with discoverability and TypeScript compatibility.
Currently forced to call the method like so in TypeScript: this.cognitoUser['getCachedDeviceKeyAndPassword']();
Most helpful comment
Could we mark
getCachedDeviceKeyAndPassword()as a public method of theCognitoUserclass? This would help greatly with discoverability and TypeScript compatibility.Currently forced to call the method like so in TypeScript:
this.cognitoUser['getCachedDeviceKeyAndPassword']();