在瀏覽器中,在Facebook登錄後,調用statusChangeCallback。一切都成功了。 Cognito甚至返回一個身份標識。但是,userPool.getCurrentUser()返回null。 Cognito認爲沒有經過認證的用戶。我該如何解決這個問題?謝謝。AWS Cognito通過Facebook驗證成功,但getCurrentUser返回null
function statusChangeCallback(response) {
if(response.status == 'connected' && response.authResponse) {
testAPI()
console.log("FB statusChangeCallback", JSON.stringify(response))
AWSCognito.config.credentials = new AWSCognito.CognitoIdentityCredentials({
IdentityPoolId : '<%=process.env.AWS_USERPOOLGUID%>', // your identity pool id here
Logins : {
'graph.facebook.com': response.authResponse.accessToken
}
});
console.log(JSON.stringify(AWSCognito.config.credentials))
AWSCognito.config.region = '<%= process.env.AWS_REGION%>'
AWSCognito.config.credentials.refresh(function(error) {
if (error) {
console.error("AWSCognito.config.credentials.get", error);
} else {
console.log("Cognito Identity Id", AWSCognito.config.credentials.identityId);
console.log('Successfully logged!');
var cognitoUser = userPool.getCurrentUser();
console.log('cognitoUser', cognitoUser);
}
});
}
}
這並不能解釋如何在點擊Facebook登錄按鈕後保護已驗證的會話和用戶,而是解釋了用戶名和密碼組合登錄。 –