Facebook Login for React Native — No Firebase Required
This guide is effective as of Jan 1, 2023
I will mention and go through all the steps which people normally forget and get stuck with, and finally give up at the end.
Create an App on Facebook Developer
Setup Facebook Login
Add Platforms (iOS & Android)
Fill up your iOS Bundle Id
Generate Key Hashes for Android & Sign your Android App
In fig: 1, You have to enter key hashes. In the next step, we will create key hashes. But keep in mind if you generate key hashes using your debug signing then facebook login will not work in release mode (apk, aab). If you want to run facebook login in release mode (which you definitely do want) then sign your app. Click Me To Sign Your App
Now, we done with signing the android app.
Now, we have to create key hashes using signing key store (that we just created above)
Open android studio
Now go to http://tomeko.net/online_tools/hex_to_base64.php
Please keep in mind, don’t enter package name until your app is not available on store. If you write your android package name then you have to confirm ownership then you can go ahead. Now save changes.
Fill up Basic Information like Privacy Policy URL
Get Advanced Access if you want to use FaceBook Login
click “Get Advanced Access” or go to “App Review” at left side and then “permissions and features” Section
Please keep in mind, if you want to get any other feature/permission of profile using facebook login then you have to get advanced access too. If you want to get user_videos then get it’s advanced access just like we did for public_profile
Make your Facebook app Live
Install package & Install Cocoapods
Now install react-native-fbsdk-next Package
yarn add react-native-fbsdk-next
Note For iOS
using cocoapods
, run:
cd ios/ && pod install
Configuration for Android
Now we have to configure for android
- Add following data to your
android/app/src/main/AndroidManifest.xml
File inside application tag
- Add following data to your
android/app/src/main/res/values/strings.xml
File inside resources
Place your facebook App Id and Facebook Client Token
Final Output of your files
Configuration for iOS
Now, we have to configure for iOS
- Add following import to your
AppDelegate.m
File according to given image
- Add following code to your same
AppDelegate.m
file insidedidFinishLaunchingWithOptions
method according to the given image
- Add following code to your same
AppDelegate.m
file afterdidFinishLaunchingWithOptions
method according to the given image
Final Output of your AppDelegate.m File
Add URL Types for iOS
- Add following lines at the end of file inside dict tag
Final Output of your Info.plist file
Now, refresh your build and re-run the App (Android & iOS Debug) Both.
Error You May Face (iOS) While Archive
Solution
Now, please add the following code snippet to your project for Facebook login.
import { LoginManager, AccessToken, AuthenticationToken } from 'react-native-fbsdk-next';
const onPress = () => {
LoginManager.logInWithPermissions(["public_profile", 'email']).then(
function (result) {
if (!result.isCancelled) {
AccessToken.getCurrentAccessToken().then(data => {
const { accessToken } = data;
// Do whatever you want with the accessToken, But in most of the cases you'll send this to back-end servers.
})
}
},
function (error) {
}
);
}
If this Medium article helped you, please just clap. Thankx.