Morpheus integrates Firebase's authentication and analytics services to allow users to securely register and access the app, and to collect data on user behavior that can be used to improve the app. Additionally, due to the integration of Excalidraw for the collaborative painting system, Firestore and Storage services are used to support it. These systems are decoupled and can be deactivated or replaced if necessary.
To enable Firebase services, you must create a Firebase project and configure the client application. The following sections explain how to do this.
Let's begin by generating the credentials for the client application. These credentials will be injected as environment variables into the Next.js application. They are required for enabling the Authentication, Analytics, Firestore, and Storage services on the client side. To accomplish this, follow these steps:
- Visit https://console.firebase.google.com/
- Create a new project.
- Assign a name to the project and follow the instructions. Makes sure to enable Google Analytics.
- In the project console, add a web application.
- Name the application and continue.
- Copy the firebaseConfig value, open the browser dev tools and convert it to a string.
- Copy the console output value and put it in the
NEXT_PUBLIC_FIREBASE_CONFIG
environment variable in/morpheus-client/env.local
The next step is to generate credentials for our server. For this, we use the Firebase Admin SDK. On the server, we will mainly use the SDK for verifying the authentication tokens of the users.
- In the project console, go to Project overview > Project Settings > Service accounts
- Choose the python option and click the "Generate a new private key" button.
- Download the JSON file, and replace the
FIREBASE_PROJECT_ID
,FIREBASE_PRIVATE_KEY
,FIREBASE_CLIENT_EMAIL
,FIREBASE_WEB_API_KEY
environment variables in/morpheus-server/secrets.env
with the values from the JSON file.
- In the 'Build' section of the sidebar, select 'Authentication'.
- Click "Get Started" to activate authentication.
- In the providers section, enable options for email and password and Google.
- For authentication to work in production, register your application's domain in Settings > Authorized Domains.
Note: Morpheus supports email and password and Google authentication by default. If you want to integrate more providers, activate them from the Firebase Auth providers section and extend Morpheus' code base.
Morpheus uses Firebase Analytics to collect data on the use of the client application. This option is activated in step 3 of the previous section. To view Analytics data:
- In the sidebar, select 'Analytics' and open the dashboard.
- In the dashboard, you will find the application usage data.
- For more details, use the "View more in Google Analytics" link at the top right.
Morpheus uses Firestore to support the collaborative painting system of Excalidraw. To activate it:
- In 'Build', choose 'Firestore Database'.
- Click "Create database", choose the location, and proceed.
- Choose 'Start in test mode' and continue.
- Add an initial record to the database.
- Complete the new record form and save it.
- Verify the new record in the database.
Firebase Storage is used to store images from the Excalidraw collaborative painting system. To activate it: