我正在使用Cognito用户池在React Native Expo应用程序中管理用户注册和登录。我也想用Facebook登录。该文档说,如果您已经在使用Cognito用户池,则无需使用Auth.federatedSignIn(),因此我不确定还需要使用什么以及如何使用?
到目前为止,这是我的代码
loginFB = async (params) => {
try {
const {
type,
token,
expires,
permissions,
declinedPermissions,
} = await Facebook.logInWithReadPermissionsAsync('414271525994061', {
permissions: ['public_profile,email'], behavior: 'native'
});
console.log('type:', type);
console.log('token:', token);
if (type === 'success') {
// Get the user's name using Facebook's Graph API
const response = await fetch(`https://graph.facebook.com/me?access_token=${token}`);
// Alert.alert('Logged in!', `Hi ${(await response.json()).name}!`);
const user = {
name: response.name,
email: response.email
};
const date = new Date();
const expires_at = expires * 1000 + date.getTime();
Auth.federatedSignIn('facebook', { token, expires_at }, user)
.then(credentials => {
console.log(credentials);
});
} else {
// type === 'cancel'
}
} catch ({ message }) {
alert(`Facebook Login Error: ${message}`);
}
}