I try to find a way to use Facebook login with Create-react-native-app for both Android and IOS. Is that possible? All this seem pretty new...
To integrate Facebook Login into a website or application you need to create a Facebook App at https://developers.facebook.com/apps/ and set up the Facebook Login product under the App. Creating a Facebook App will provide you with a Facebook App ID which is required when initializing the Facebook JavaScript SDK ( FB.
Before getting started, ensure you have installed the library, configured your Android & iOS applications and setup your Facebook Developer Account to enable Facebook Login. Ensure the "Facebook" sign-in provider is enabled on the Firebase Console.
Originally, Facebook only developed React Native to support iOS. However, with it's recent support of the Android operating system, the library can now provide mobile UIs for both platforms. Facebook used React Native to develop its own Ads Manager app, creating both an iOS and an Android version.
Use the Expo SDK. This way you won't have to eject from create-react-native-app.
import { Facebook } from 'expo';
async function logIn() {
const { type, token } = await Facebook.logInWithReadPermissionsAsync('<APP_ID>', {
permissions: ['public_profile'],
});
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}!`,
);
}
}
Snippet taken from the link.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With