Facebook Login
Integrate Facebook login in Ionic 5 apps
Last updated
Integrate Facebook login in Ionic 5 apps
Last updated
Steps to follow for adding facebook login
The first thing we need to do is to create a new application in Facebook’s developer dashboard, and this app is the one that Facebook will use to ask our users for their permission when we try to log them into our Ionic application.
For that you’ll need to go to facebook developer console and create a new app.
Once we finish creating our app, we will go to facebook app dashboard and take app id from there. It will help us in installing Facebook plugin in our app
In this step we will install the Cordova plugin in our Ionic app.
For that, open your terminal and type
You’ll need to replace the values or APP_ID
and APP_NAME
for your real credentials. You can find both of those inside your Facebook Developers Dashboard.
It's bit clumsy to work with cordova plugin so ionic team created Ionic Native, which is a wrapper for the Cordova plugins so we can use them in a more “Angular/Ionic” way.
So now we will open our terminal and try this command
for installing facebook package from Ionic Native
Once everything is set up in our development environment, we need to let Facebook know which platforms we’ll be using (if it’s just web, iOS, or Android).
In our case, we will add all three platforms iOS , web and Android.
To add the platforms, go ahead and inside your Facebook dashboard click on settings, then, right below the app’s information you’ll see a button that says Add Platform, click it.
To add the platforms, go ahead and inside your Facebook dashboard click on settings, then, right below the app’s information you’ll see a button that says Add Platform, click it.
Once you click the button, you’ll see several options for the platforms you’re creating
, let’s start with iOS, you’ll see a form asking you for some information, right now we just need the Bundle ID
.
If you don’t know where to get the Bundle ID, it’s the same as the package name when you create an Ionic app, it’s inside your config.xml
file:
Once you add the Bundle ID, just follow the process to create the app.
for Android, the difference is that instead of Bundle ID
, Android calls it “Google Play Package Name.”
Now that everything is set up on Facebook’s side, we need to go into our Firebase console and enable Facebook authentication for our app.
To enable Facebook, you’ll need to go to your Firebase Console and locate the app you’re using.
Once you’re inside the app’s dashboard, you’re going to go into Authentication > Sign-In Method > Facebook and are going to click the Enable toggle.
It will ask you App ID and App secrete you will copy it from your Facebook console, under your app’s settings.
The first thing we need to do is to get the authorization token from Facebook, to do that, we need to import Facebook plugin from Ionic Native and ask our user to log in.
This function first we will check platform of user if it is browser then we will open pop up for facebook log in and if it is IOS or android platform then we follow native facebook login process which will give you Firebase Token and from this token we will login user to firebase app