Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用Cognito和AWS Amplify在社交登录中获取和传递deviceKey?_Javascript_Reactjs_Amazon Web Services_Amazon Cognito_Aws Amplify - Fatal编程技术网

Javascript 如何使用Cognito和AWS Amplify在社交登录中获取和传递deviceKey?

Javascript 如何使用Cognito和AWS Amplify在社交登录中获取和传递deviceKey?,javascript,reactjs,amazon-web-services,amazon-cognito,aws-amplify,Javascript,Reactjs,Amazon Web Services,Amazon Cognito,Aws Amplify,我试图在社交登录中使用Cognito中的函数setDeviceStatusMembered,但它需要一个deviceKey,而在返回的用户对象中不可用 该项目是使用React创建的。我已经尝试了StackOverflow和docs的一些响应,但没有成功 用户由Amazon通过OAuth在social login中处理和创建,登录后,我将通过以下方式获取用户数据: const cognitoUser = await Auth.currentAuthenticatedUser() 之后,对象cog

我试图在社交登录中使用Cognito中的函数
setDeviceStatusMembered
,但它需要一个deviceKey,而在返回的用户对象中不可用

该项目是使用React创建的。我已经尝试了StackOverflow和docs的一些响应,但没有成功

用户由Amazon通过OAuth在social login中处理和创建,登录后,我将通过以下方式获取用户数据:

const cognitoUser = await Auth.currentAuthenticatedUser()
之后,对象
cognitoUser
显示
deviceKey
null,如果我尝试以下代码,我会收到错误消息
“检测到1个验证错误:'deviceKey'处的值null未能满足约束:成员不能为null”

我怎样才能解决这个问题?我错过什么了吗?
谢谢。

首先,请确保您的用户池已配置为记住设备。如果通过放大设置身份验证,则默认情况下可能会禁用此选项。以下是如何在AWS控制台中启用它:

您可以从用户对象获取设备密钥:

Auth.currentAuthenticatedUser({
}).then(user => {
  user.getCachedDeviceKeyAndPassword(); // without this line, the deviceKey is null
  console.log(user.deviceKey);
});
Auth.currentAuthenticatedUser({
}).then(user => {
  user.getCachedDeviceKeyAndPassword(); // without this line, the deviceKey is null
  console.log(user.deviceKey);
});