In process of expanding features of loklak to provide support of twitter api to the users, it was a good idea to go with Firebase as the managing medium for logged in or authenticated users. After integration of Firebase into loklak, users will be able to authenticate themselves securely with Facebook, Google, and Twitter and get access to the results from Twitter api on loklak. In this blog post, I will be discussing the Firebase configuration process into loklak.
Setting up Firebase environment configuration
Without explicitly going into each single detail of the integration process which is already provided by Firebase and other mediums, I will jump on to the main key characteristics of configuring Firebase into Loklak. This step covers the configuration of Firebase environment parameters. Goto Firebase console and copy the project’s environment’s parameters for web app option and paste it into environments/environment.ts file inside the project as given below by replacing all ‘*’ with the required values.
Initialise the Firebase app
Next step would be to cover establish the Firebase app in app.module.ts by importing necessary packages as given below.
Creating Auth service with various Auth providers
This is the main part of the Firebase configuration. Create a new Auth service in ‘services/’, and include the given below methods for providing authentication using – Twitter, Facebook, Google, and Email & Password. We will also provide logout feature for the user to log out from the current service provider. Given below is an example of adding Google as the service provider for authentication, it can be similarly used to provider authentication for other providers.
We are using AngularFireAuth to provide authentication for every provider.
Using Auth service in the required component
This step would cover up the last portion to use the auth service to actually provide authenticated login. Now, import the created auth service and other packages and create a property of auth service and a user variable to keep check on the current user status (We would store the current status on the constructor call).
Now, call the methods of auth service and storing the status of current user in the user property created above (For an example, calling only twitter auth and logout method).
These methods could now be easily called inside (click) property of any appropriate html div/tag to provide login or logout feature.
Testing Auth Login
Click on the div/tag which is calling the SignIn methods and look onto the console for results.