UTM CSSC

Firebase

Behind the Scenes with Voting

Reading Flowchart

Firebase Setup

  • Create a Google account if the user does not already have one

  • Go to firebase.google.com

  • Click Go to console on the top right corner of the Firebase website

    Firebase Home Page

  • Select Add project

    • Follow the displayed instructions Add project page
  • Once the project has been created, select the project to navigate to the project's home page

  • Create a new web application:

    • Select the web application icon Create web application
    • Register the application under the displayed instructions
    • Copy the credentials that are given (They should match the Environment Variables)
  • Create a new firestore:

    • Select Cloud Firestore on the sidebar Cloud Firestore Side Bar
    • Select Create Database
    • Start in test mode
    • Select a location
    • Click enable
  • Database Layout

  |-Voting (Collection)
    |- 2020 (Document)
      |- Month (Collection)
        |- Option 1 (Document)
          |- Active: true/false (Field)
          |- Vote: 0 (Field)
        |- Option 2
          |- Active: true/false
          |- Vote: 0
    |- Subscription (Document)
      |- Email

Notes:

  • For the month you wish to set it up for, if the current date is between 15-30/31, enter the next month. If the current date is between 1-14, then create a collection under the current month.
  • The user collection will automatically be created when a user votes
  • There is no limit to the number of voting options that you can create Database Example 1 Database Example 2

Authentication:

In order to enable authentication:

  • Navigate to the project on the Firebase Website
  • Select authentication Authentication Side Bar
  • Switch to the sign-in method
  • Enable Google sign-in
    • Note: If the user wishes to use the Github login, follow the instructions that Firebase provided to enable the Github login
  • Uncomment the login provider they wish to use (make sure the corresponding provider is enabled on Firebase)

/plugins/firebase.js (In the plugins folder)

// export const provider = new firebase.auth.GithubAuthProvider()
// export const provider = new firebase.auth.OAuthProvider('microsoft.com')
// export const provider = new firebase.auth.GoogleAuthProvider();
export const auth = firebase.auth()
User can switch between the authentications (Github/google).

Environment Variables

.env

  • The .env file is used to load in our environment variables to connect to Firebase. This file is not meant to be exposed to the public
Env NameAbout
API_KEYAPI Key given by Firebase
AUTH_DOMAINAuthentication domain
DATABASE_URLURL for the database
PROJECT_IDProject Name/ID
STORAGE_BUCKETThe storage bucket link
MESSAGING_SENDER_IDThe messaging sender ID
APP_IDThe application ID

Possible Responses

Successful messages:

The following are success messages that you may encounter when voting or subscribing to the email list

  • Vote has been submitted
  • Unsubscribed!
  • Subcribed!

Failure Messages:

The following are failure messages you may encounter when voting, subscribing to the email list, or if there was an internal server error

  • Could not connect to the database
  • Internal server error. Please try again
  • Please sign in if you wish to vote
  • Please select an option for each choice
  • You have already voted, your current votes are...
  • The options were recently changed, please revote, your current votes are... Would you like to revote?
  • You are already subscribed, would you like to unsubscribe
  • Invalid email
  • You are not subscribed