Follow these steps if you're using Firebase Auth or Cloud Firestore
- Click the "Get Started" button
- Click the "Create a project" button
- Give your project a name and click "Continue"
- Toggle Google Analytics off for this project. If you'd like to use Google Analytics, we'll be setting this up separately so that we can configure it correctly for your Divjoy codebase.
- Click "Continue" after Firebase is done setting up your new project.
- Click the gear icon and then "Project settings"
- At the bottom of the screen click the "</>" icon to create a web app
- Name your web app. If your Firebase project was called "Lyft", you might name it "Lyft Web". Don't check the Firebase Hosting checkbox. Finally, click the "Register app" button.
- Click "Continue to console". You don't need to copy and paste these scripts into your code. We'll have you add the required values as environment variables in the next step.
- Go to project settings. Scroll down to the "Your Apps" section and copy the values for
authDomaininto your codebase
.env file should now look like this:
You also need to add these values to the bottom section of your
.env. This section determines what values are included in your client-side JS. By specifying them separately we ensures that any values we don't want to expose (such as private keys) are kept server-side only.
- Click the "Service accounts" tab under the big "Project settings" header and then click the "Generate new private key" button at the bottom.
- Click the "Generate key" button
client_emailvalues into your codebase
.envfile. This is necessary for any server logic that needs to talk to Firebase.
- The file should look something like this. You need to copy the entire value between the quotes, including the
----BEGIN PRIVATE KEY-----\nand
\n-----END PRIVATE KEY-----\nportions.
.env file should now look like this:
Follow these steps if you're using Firebase Auth (skip if using a different auth provider)
- Click "Build" then "Authentication in the left-hand column
- If you see this introductory screen you'll need to click "Get started"
- Go to the "Sign-in method" tab
- Click "Email/Password", toggle the "Enable" switch, and click "Save".
- For example, to get Twitter auth working you'll need to go to https://developer.twitter.com, create an app, then fill in the API Key and API secret.
http://localhost:3000/firebase-action. This page is automatically inserted by Divjoy when you export your codebase.
- Go to the "Templates" tab and then click the edit button (pencil icon) on the right side.
- Click the small "Customize action URL" link at the bottom.
- Add a URL that points to the /firebase-action page in your codebase and then click "Save". For testing this locally you'll want to use your localhost URL. You can change this later to your production URL or have a separate Firebase app for production.
- Important: If you're using Cloud Firestore then authentication will not work until that is setup. The auth logic we give you in
src/util/auth.jsautomatically merges extra user data from Cloud Firestore and will fail if it's unreachable. Continue on to the next section to setup Cloud Firestore.
Follow these steps if you're using Cloud Firestore (skip if using a different database provider).
- Click the "Cloud Firestore" link on the left and then click "Create database".
- Select "Start in test mode" and then click the "Next" button. We'll give you the rules to secure your database in a following step.
- Pick the Cloud Firestore location closest to your servers and then click "Enable". If not sure, then just go with the default.
firestore.rulesfile. This ensures that your users cannot read or edit data that they shouldn't have access to.
- It should look like this after pasting in the contents of your
firestore.rulesfile. Click the "Publish" button to push these new rules live.
Just click "Get started" and then you're done with this step
itemscollection on the fields
createdAt (descending). This is required so that your
useItemsByOwnerfunction can properly fetch a user's items and sort by date created. You'll see an example UI that utilizes this database logic in the dashboard page of your codebase.
- Click the "+ Create index" link
- Fill in the form as you see below and then click the "Create index" button. Remember that the
createdAtfield should be
- After creating the index you'll notice it says it has a status of "Building". You're safe to close this page and continue setting up your app. It should switch to "Enabled" in a few minutes.
If you're using Cloud Firestore as your database provider then the auth logic we give you in
src/util/auth.js automatically merges extra user data from Cloud Firestore and will fail if it's unreachable (causing it to be stuck in a loading state). You can check as to whether this is the issue by temporarily setting
const MERGE_DB_USER = false in
src/util/auth.js. To resolve this issue you'll want to follow the Cloud Firestore instructions above. After the setup, make sure you delete any account from Firebase Authentication that you've created while encountering this bug.
Make sure that all environment variables for all the services in your
.env file have values filled in. Also make sure the variables at the bottom (starting with
NEXT_) have values filled in. Ensure the values are correctly formatted by comparing them to what you see in this screenshot (for example the `authDomain` value shouldn’t start with "https://").
You can disable this by going to
src/util/auth.js and setting
const EMAIL_VERIFICATION to
Assuming you are using the authentication components from the Divjoy library, you just need to go to
src/pages/auth.js and update the providers array on the
AuthSection component. For example, here's what it would look like if you want to display options for Google, Facebook, and Twitter.
Our authentication component supports the following by default:
github. You can add more options by configuring them in Firebase and then following this guide to display them in your component: Adding new login providers to Firebase.