问题
I am trying to use the function setDeviceStatusRemembered from Cognito in the social login, but it needs a deviceKey, which is not available in the user object returned.
The project is made using React. I already tried some responses from StackOverflow and docs, but no success.
The user is handled and created by Amazon via OAuth in social login, and after login, I am getting the user data with this:
const cognitoUser = await Auth.currentAuthenticatedUser()
After, the object cognitoUser shows the deviceKey null, and if I try the following code, I get the error message "1 validation error detected: Value null at 'deviceKey' failed to satisfy constraint: Member must not be null"
cognitoUser.setDeviceStatusRemembered({
onSuccess: function (result) {
console.log('call result: ' + result);
},
onFailure: function(err) {
console.log('call error', err);
}
})
How can I solve this problem? Am I missing something? Thanks.
回答1:
First of all, make sure that your user pool is configured to remember devices. If you set up Auth through Amplify this is probably off by default. Here's how it is enabled in the AWS console:
You can get the device key from the user object:
Auth.currentAuthenticatedUser({
}).then(user => {
user.getCachedDeviceKeyAndPassword(); // without this line, the deviceKey is null
console.log(user.deviceKey);
});
来源:https://stackoverflow.com/questions/56451317/how-to-get-and-pass-devicekey-in-social-login-using-cognito-and-aws-amplify