Firebase Functions

Learn what Firebase functions are used in Taxi booking platform

There are several functions that are performed using Firebase cloud functions. Before making changes in the functions or running the app, make sure you deploy the Firebase functions to your own firebase project.

Deploying Firebase functions

Firebase functions can be used after you install Firebase-tools in your system globally

$ npm install firebase-tools -g

A firebase function can be deployed by running the command

$ firebase deploy --only functions

You can confirm the deployment of your functions by checking in the Firebase console. It will show you a list of all functions you deployed. For Taxi Booking Platform, it should show you total 5 functions as following

Replace function calls in the app

Once you deploy your functions, every function will get a unique URL for calling. Make sure you replace the existing function call URLs with these new URLs, otherwise the app will keep calling the old Firebase project only.

You can find out the existing Function URLs by searching for https://us-central in the whole app. Replace all instances of old URLs you find.

To learn how to deploy a Firebase function in detail, check out our blog - Firebase Cloud function in Ionic 4

Details of Firebase functions used

Following are the cloud function being used in Taxi Booking Platform

  1. getDriver - This function is called when user books a ride. This function updates the user and Driver data to show that a ride is being requested. The response of this function is the driver's data.

  2. rejectRide - When driver rejects a ride, this function is called. This updates user and driver records, showing that Driver is now available for new ride, and user can also book a different ride.

  3. acceptRide - When driver accepts a ride, this function is called. This updates user and driver records, showing that Driver is now not available for new ride, and user can also not book a different ride.

  4. drivernotRespond - When driver does not respond to a ride request for a specific amount of time set in the app, this function is automatically called. This function cancels the ride and shows an alert to the user that "Driver did not respond"

  5. completeRide - This function is called when a ride is completed from Driver's side. This ends the ride for User and Driver both, updates their record to show that Driver is now available for a new ride and User can now book a new ride.

To know more about how to create, implement, deploy and test Firebase cloud functions, please refer to out blog - Firebase Cloud function in Ionic 4