Javascript 如何使用Cognito和AWS Amplify在社交登录中获取和传递deviceKey?
我试图在社交登录中使用Cognito中的函数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
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);
});