簡體   English   中英

如何使用Cognito和AWS Amplify在社交登錄中獲取和傳遞deviceKey?

[英]How to get and pass deviceKey in social login using Cognito and AWS Amplify?

我試圖在社交登錄中使用Cognito中的函數setDeviceStatusRemembered ,但它需要一個deviceKey,它在返回的用戶對象中不可用。

該項目是使用React制作的。 我已經嘗試過StackOverflow和docs的一些回復,但沒有成功。

用戶由社交登錄中的OAuth通過OAuth處理和創建,登錄后,我將獲取用戶數據:

const cognitoUser = await Auth.currentAuthenticatedUser()

之后,對象cognitoUser顯示deviceKey null,如果我嘗試以下代碼,則會收到錯誤消息"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);
   }
})

我怎么解決這個問題? 我錯過了什么嗎? 謝謝。

首先,確保您的用戶池配置為記住設備。 如果您通過Amplify設置Auth,則默認情況下可能已關閉。 以下是在AWS控制台中啟用它的方式:

截圖AWS控制台

您可以從用戶對象獲取設備密鑰:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM