
Before you begin
- Labs create a Google Cloud project and resources for a fixed time
- Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
- On the top left of your screen, click Start lab to begin
Register your app
/ 30
Set up authentication
/ 35
Add a customer page to your web app
/ 35
Twelve years ago, Lily started the Pet Theory chain of veterinary clinics. The Pet Theory chain has expanded rapidly over the last few years. Their old appointment system is not able to handle the increased load or allow clients to schedule their own appointments, so Lily asked Patrick, in IT, and Ruby, a consultant, to build a cloud-based system that easily scale. In this lab you will build a fully fledged Firebase web app that allows users to log information and schedule appointments in real time.
This diagram gives you an overview of the services you will be using and how they connect to one another:
In this lab, you will learn how to:
This is a intermediate level lab. This assumes familiarity with the Cloud Console and shell environments. Experience with Firebase will be helpful, but it is not required. Before taking this lab it is recommended that you have completed the following lab:
You should also be comfortable editing files. You can use your favorite text editor (like nano
, vi
, etc.) or you can launch the code editor from Cloud Shell, which can be found in the top ribbon:
Once you're ready, scroll down and follow the steps below to setup your lab environment.
Ruby sends Patrick an email:
Ruby, Software Consultant |
Hi Patrick, Awesome work last week. Great to see that the clinic's data has been migrated to Firestore! It looks like the next task is to use Firebase to host the Pet Theory website. Ruby |
Patrick, IT Administrator |
Hi Ruby, I haven't heard of Firebase hosting before, what are the benefits? Where would I get started? Patrick |
Ruby, Software Consultant |
Hi Patrick The primary benefit of Firebase hosting is that it is serverless, so there is no infrastructure to manage. Security rules are also embedded within the application, so permissions can be restricted to minimize issues when handling customer data. It also has a "pay as you use" model, which means Firebase is a comprehensive mobile development platform for our use case. Ruby |
Patrick, IT Administrator |
Hi Ruby Sounds like Firebase will make security and infrastructure management (a big part of my job) a whole lot easier. I'm excited to not be billed for idle servers either! Patrick |
Ruby sends Patrick some background information in an email, and they hold a meeting to work out the key activities. From this meeting they determine that he needs to:
Next, help Patrick accomplish these tasks.
Open an incognito window to access the Firebase Console url Firebase Console.
When requested enter the:
From the Firebase Project Overview screen, enter the following commands:
Select the web icon (highlighted below) from the list of "Get started by adding Firebase to your app" icons:
When prompted for an "App nickname", type in Pet Theory.
Check the box next to "Also set up Firebase Hosting for this app".
Click the deploy dropdown and select Create a new site
.
Amend the default to include the student prefix.
Click on the Register app button.
Click Next > Next > Continue to console.
firebase.json
to include the custom site ID. Set up deploy targets for your sites
firebase deploy --only hosting:student-bucket- -1
You have now configured the Firebase application.
Click Check my progress to verify the objective.
In the Firebase Console we will setup Firebase Authentication.
Click on the Build dropdown button in the left-hand navigation panel.
Select Authentication tile and then click on Get Started:
Click on Sign-in method tab and then, click on the Google item.
Click the enable toggle in the top right corner and for the Support email for project select your lab account from the drop down list.
Your page should now resemble the following:
Once you have verified the above, click on the Save button.
Click the Settings tab
Under the Domains heading, click the Authorized domains menu item
Your page should now resemble the following:
Click the Add domain button
Enter the following domain:
Click the Add button
Click Check my progress to verify the objective.
In the Firebase Console we will setup Firebase Authentication.
Click on the Build dropdown button in the left-hand navigation panel.
Select Firestore Database tile and then click on Create database:
Accept the default settings and click Next
Click Create to provision Cloud Firestore
Click the Rules tab
Update the rules as follows:
You have now set up Firebase Authentication and Firestore with a custom site identifier. The backend configuration is now complete.
You have assisted Patrick in setting up a working Firebase hosting environment where a web developer can deploy their code.
However, Patrick has never enabled Firebase authentication nor has he deployed code to Firebase, so he emails Ruby for some help...
Patrick, IT Administrator |
Hey Ruby, Thanks for all the tips! The Firebase environment looks like it is all set up. My next task is to deploy the website developers' code. Can you help me understand what this entails and what I need to do next? Patrick |
Ruby, Consultant |
Hi Patrick, That's great to hear! I'll send you the instructions on how to run the application and add the following features:
Ruby |
Patrick, DevOps Engineer |
Hi Ruby That sounds like it will be quite a bit of work. Does that mean I'll have to make structural changes every time I want to add something new? Not to mention the time it will take to see those updates... Patrick |
Ruby, Consultant |
Hey Patrick You can do most of the heavy lifting with Firebase libraries. Firebase has some great command line tooling to help you connect your localhost to the backend Firebase project. Use Once your project is set up you can simply call Ruby |
Patrick, IT Administrator |
Hi Ruby Wow, that's very comforting! Firebase hosting just gets better and better :-) Patrick |
Use the IDE to connect to Firebase and deploy your application.
Copy the IDE link from the Lab Details panel
Paste the link into a new incognito browser tab to open Cloud Code.
Open a Terminal by Clicking the Application menu () > Terminal > New terminal.
Clone the GitHub repository from the command line:
In the left panel, click the Explorer icon, and then Open Folder > pet-theory > lab02. Click OK.
Do you trust the authors of the files in this folder?
then check the box and click Yes, I trust the authors.
Open a terminal again by clicking the Application menu () > Terminal > New terminal.
Update the node packages:
Example Output:
You are now ready to link the application to the backend Firebase project.
In the IDE connect Firebase and deploy your application.
Type the following command to authorize Firebase project access:
Enter in Y if asked if Firebase can collect error reporting information and press Enter.
Copy and paste the URL generated into a new incognito browser tab then press Enter (directly clicking on the link results in an error).
Select your lab account then click Allow.
Click on Yes, I just ran this command to proceed
6 Confirm your session ID by clicking Yes, this is my session ID.
You will then be given an access code:
Copy the access code then paste it in the Cloud Shell prompt Enter authorization code:, and press Enter.
You should receive output similar to the following response:
Example Output:
Firebase is now connected and authorized. The next step is to initialize the Firebase products to be used.
In the IDE let Firebase know which products are required.
Initialize a new Firebase project in your current working directory:
We need the following products:
Use the arrow keys and the spacebar to select Firestore and Hosting. Ensure your shell matches the following and then hit Enter:
Run through the rest of the steps to configure Firebase:
Example Output:
The local configuration is now complete.
Continue in the Terminal for this step. Ensure you are still in the pet-theory/lab02 folder.
Edit firebase.json and update the hosting section with the site
Expected Output
Deploy your firebase application, using your site ID value e.g.:
Output:
Copy the hosting URL (should resemble
Click on the Sign in with Google button:
Login with your username provided i.e.
A small company like Pet Theory doesn't have the resources or requisite skill set to do this. In this instance it can be beneficial to let application users log in with their existing Google account (or any other identity providers)!
You have now deployed code to let users use Google authentication to access the appointments app.
Return to the Terminal and use the editor to view the files in the public folder.
Open the public/customer.js
file and copy and paste the following code:
Open the public/styles.css
file and paste in the following code:
From the Terminal command line run the following command:
Output:
Go to your application tab and hard refresh the page with CMND+SHIFT+R (Mac) or CTRL+SHIFT+R (Windows). Simple refreshing will not display the needed updates.
Enter some customer info—make up a name and phone number
Customer name:
Customer phone:
Click Save profile.
Return to the Firebase Console
Click Build > Firestore Database to view the profile information saved:
Return to the web app page and click on the Appointments link. You will see a blank page since it has not deployed the appointments code yet.
Click Check my progress to verify the objective.
Pretty cool!
Firestore updates clients (web apps and native mobile apps) in real time, without the user having to refresh or reload.
Throughout the course of this lab, you created a robust serverless web application with Firebase. After creating and configuring a Firebase Project, you added Firestore security to automate server-side authentication and authorization. You then went ahead and added Google Sign-in to your web app and configured your database so users can add contact info and appointments. Finally, you explored and deployed code that allows users to schedule appointments and saw Firebase's real time updates in your web app. You are ready to take more labs in this learning path.
...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.
Manual Last Updated Oct 16, 2024
Lab Last Tested Oct 16, 2024
Copyright 2025 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.
This content is not currently available
We will notify you via email when it becomes available
Great!
We will contact you via email if it becomes available
One lab at a time
Confirm to end all existing labs and start this one