Skip to content

Latest commit

 

History

History
182 lines (117 loc) · 4.92 KB

File metadata and controls

182 lines (117 loc) · 4.92 KB

Configuring Firebase

Firebase is used to configure authentication in the front-end app, allowing users a plethora of options for logging in to our app and creating accounts.

Now that we have a GCP project and custom domains set up, we can fully configure Firebase, which will give us several things:

  • A publicly-viewable "config" object for our client-side web app
  • Another service account for server-side auth middleware

For this tutorial, we assume that we want to offer users several strategies for signing on...

  • Email & password signup
  • Google SSO

... but you are free to choose your own sign-on strategies.

Table of Contents

  1. Initialize Firebase
  2. Set up authentication
  3. Enable storage
  4. Configure the web app
  5. Create a service account

1. Initializing Firebase

Visit console.firebase.google.com to get started. We will want to select "Add project".

new instance

Next, search for and select the name of the GCP project we previously created and click "Continue".

find project

continue project

Take note of the "a few things to remember" - especially the warning that if you delete your Firebase project, it will delete the associated GCP project. Then click "Continue".

warnings

Now decide on whether or not you want to enable analytics and click "Continue".

enable analytics

2. Set up authentication

From the project overview, select "Authentication" from the sidebar menu.

select authentication

Then click "Get started" to... get started.

get started

Next, select "Email/Password".

select email & password

We will choose not to allow password-less sign-on, but feel free to do so. Select "Enable" and then click "Save".

save email & password

To add another strategy, for instance Google SSO, select "Add new provider" and follow the instructions.

add another provider

When you are done configuring log-in options, now add the same domain used for the web front-end when configuring DNS for domain-mapping as an authorized domain.

Following the previous tutorial, we would click "Add domain", fill in dev.example.com, and click "Add".

add authorized domain

3. Enable storage

Next we need to configure storage rules. In the sidebar menu, select "Storage" and then click "Get started".

storage get started

We cannot alter the rules here, so just click "Next".

next modal

Now select a region for storage and click "Done". It probably makes sense to select the same region that your base GCP project is in.

select region

Next, select the "Rules" tab.

select rules

Now copy the following rules...

rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /assets {
      allow read, write;
      match /{allPaths=**} {
        // Allow access by all users
        allow read, write;
      }
    }
	match /users/{uid}/{profileImage} {
      allow read, write;
    }
  }
}

... and paste into the editor field and click "Publish".

publish rules

4. Configure the web app

In the sidebar menu, select "Project settings".

select project settings

Scroll to the bottom of the page and select the "</>" button to configure a new web app.

add web app

Add a nickname for the web app and select "Register app".

register app

Next, copy the highlighted public, client-side config object and save somewhere - we will need this later when configuring Github Secrets.

After saving the configuration details, select "Continue to console".

copy config

5. Create a service account

Once more, go into "Project settings", select the "Service accounts" tab, and then click "Generate new private key".

generate private key

Click "Generate key" and then save the resulting JSON somewhere - we'll need this as well when configuring Github Secrets.

save private key

If you then visit console.cloud.google.com and click through to "IAM & Admin -> Service Accounts" you should see a new service account linked to Firebase.

firebase service account


Next Up

Assigning Github Secrets