> For the complete documentation index, see [llms.txt](https://will-schneider.gitbook.io/react-saas/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://will-schneider.gitbook.io/react-saas/getting-started.md). Agents can also search and read this documentation through its [MCP server](https://will-schneider.gitbook.io/react-saas/~gitbook/mcp).

# Getting Started

![Diagram](https://storage.googleapis.com/images-reactsaas/diagram.png)

{% embed url="<https://youtu.be/ZUC3VsepYFY?si=FW3phvqGFkUC-K-x>" %}

1. Download the template locally from your Dashboard

   * Update the directory name for the downloaded code to whatever you want

   ```bash
   cd <project-directory>
   ```

   * Optional: Run setup script to get started fast or continue manually

     * MacOs: setup.sh

     ```bash
       chmod +x setup.sh
       ./setup.sh
     ```

     * Windows: setup.ps1

     ```powershell
       Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process
       .\setup.ps1
     ```
2. Set up your development environment variables:
   * Copy the contents of **env.example** to a new file named **.env.local**
   * Create a Firebase account at <https://firebase.google.com/>
   * Create a new Firebase project for your app's development environment
     * Suggested name: \[project]-dev
     * Do not need Firebase hosting
   * In Firebase console, go to Project Overview > Add app > Web
   * Copy the configuration values provided
     * Everything inside the brackets of firebaseConfig
   * Paste these values into your **.env.local** file, replacing the placeholders
     * Ensure all variable names are in uppercase and prefixed with NEXT\_PUBLIC\_
     * Reference: <https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables>
3. Configure Firebase services:
   * In Firebase console, enable Authentication and add the Email/Password sign-in method
   * Create a default Firestore Database in your preferred region
     * Choose "Start in production mode"
   * Set up Firestore security rules:
     * Go to Firestore Database > Rules
     * Replace the default rules with the following template for user-specific data access control:
4. Under Firestore security rules add the following in place of the default rules:

   ```
   service cloud.firestore {
     match /databases/{database}/documents {
       match /users/{userId}/{document=**} {
         allow read, write: if request.auth != null && request.auth.uid == userId;
       }
       
       match /customers/{uid} {
         allow read: if request.auth.uid == uid;

         match /checkout_sessions/{id} {
           allow read, write: if request.auth.uid == uid;
         }
         match /subscriptions/{id} {
           allow read: if request.auth.uid == uid;
         }
         match /payments/{id} {
           allow read: if request.auth.uid == uid;
         }
       }

       match /products/{id} {
         allow read: if true;

         match /prices/{id} {
           allow read: if true;
         }

         match /tax_rates/{id} {
           allow read: if true;
         }
       }
     }
   }
   ```
5. Run the development server:

   ```bash
   npm i
   npm run dev
   ```
6. Open <http://localhost:3000> in your browser to see the result.
7. Create your production environment:
   * Repeat steps 2-4 to set up your production environment
   * Create a separate prod Firebase project
     * Suggested name: \[project]-prod
   * Update **.env.local** with the production environment variables
8. Add version control and save your progress on Github:

   * Create a private Github Repo: <https://github.com/new>
   * Initialize the code with Git then push it to Github:

   ```bash
   git init
   git remote add origin <your-github-url>
   git branch -M main
   git add .
   git commit -m 'Adding the template code to my repo'
   git push -u origin main 
   ```
9. Create shareable URLs for your web application, synced with Github (CI/CD).
   * Import your Git Repository into Vercel: <https://vercel.com/new>
     * You will need the Vercel application added to your GitHub account
     * Copy and paste your dev environment variables from **.env.local** into Vercel
       * Select Development and Preview in Vercel
       * Add NEXT\_PUBLIC\_ENVIRONMENT="DEV" in Vercel
       * Push to a different branch to get the first preview URL

<figure><img src="https://1699355075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu5ZFqXvi6XrDDrmKerRj%2Fuploads%2FN4TfzJapOIfRobL9Xdqj%2Fenv-vars.png?alt=media&amp;token=c7a2bdae-fbc6-41d8-bd61-05b8621f2a6e" alt=""><figcaption></figcaption></figure>

* Copy and paste your prod environment variables from **.env.local** into Vercel
  * Select Production in Vercel
  * Add NEXT\_PUBLIC\_ENVIRONMENT="PROD" in Vercel
  * Prod will be deployed to your main branch

<figure><img src="https://1699355075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu5ZFqXvi6XrDDrmKerRj%2Fuploads%2FRtn30qvLP1ev9iaml0QO%2Fprod-env-vars.png?alt=media&amp;token=fbdffc39-eafc-48ff-a18d-0d92e8285d26" alt=""><figcaption></figcaption></figure>

* Click Deploy in Vercel

10. Start creating new branches with code updates for version control and staging domains
