如何使用Cognito和AWS Amplify在社交登录中获取和传递deviceKey? [英] How to get and pass deviceKey in social login using Cognito and AWS Amplify?

查看:198
本文介绍了如何使用Cognito和AWS Amplify在社交登录中获取和传递deviceKey?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在社交登录中使用Cognito的函数 setDeviceStatusRemembered ,但是它需要一个deviceKey,该密钥在返回的用户对象中不可用。

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.

该项目是使用React进行的。我已经尝试过StackOverflow和文档的一些响应,但是没有成功。

The project is made using React. I already tried some responses from StackOverflow and docs, but no success.

用户是通过Amazon在社交登录中通过OAuth处理和创建的,登录后,我得到了用户数据:

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()

之后,对象 cognitoUser 显示 deviceKey null,如果尝试以下代码,则会收到错误消息检测到1个验证错误:'deviceKey'的值null无法满足约束:成员不能为null

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.

推荐答案

首先,请确保将用户池配置为记住设备。如果您通过Amplify设置Auth,则默认情况下可能处于关闭状态。在AWS控制台中启用它的方式如下:

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

这篇关于如何使用Cognito和AWS Amplify在社交登录中获取和传递deviceKey?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆