-
Notifications
You must be signed in to change notification settings - Fork 0
Setup Guide
Complete guide to set up and configure your Firebase React application from scratch.
- Prerequisites
- Initial Setup
- Firebase Project Setup
- Environment Configuration
- Local Development
- Verify Setup
Before starting, ensure you have:
- Node.js (v18 or higher) - Download
- npm (comes with Node.js) or yarn
- Git - Download
- Code Editor - VS Code recommended
- GitHub Account - For version control
- Google Account - For Firebase access
npm install -g firebase-toolsVerify installation:
firebase --versiongit clone https://github.com/ThanuMahee12/firebase-react-template.git
cd firebase-react-templateUsing npm:
npm installUsing yarn:
yarn installThis will install all dependencies listed in package.json:
- React & React DOM
- Firebase SDK
- Redux Toolkit & React-Redux
- React Router DOM
- React Icons
- Vite & Build tools
- Go to Firebase Console
- Click "Add Project" or "Create a project"
- Enter project name (e.g.,
my-awesome-app) - Disable Google Analytics (optional for free tier)
- Click "Create Project"
- Wait for project creation
- In Firebase Console, click the Web icon
</> - Enter an App nickname (e.g.,
My App) - Don't check "Also set up Firebase Hosting" (we'll do this later)
- Click "Register app"
- Copy the configuration object - you'll need this soon
Example configuration:
{
apiKey: "AIzaSyXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
authDomain: "my-app-12345.firebaseapp.com",
projectId: "my-app-12345",
storageBucket: "my-app-12345.appspot.com",
messagingSenderId: "123456789012",
appId: "1:123456789012:web:abcdef123456"
}- In Firebase Console sidebar, click "Authentication"
- Click "Get started"
- Click on "Sign-in method" tab
- Enable "Email/Password":
- Click on "Email/Password"
- Toggle "Enable"
- Click "Save"
-
(Optional) Enable "Google" sign-in:
- Click on "Google"
- Toggle "Enable"
- Select your support email
- Click "Save"
- In sidebar, click "Firestore Database"
- Click "Create database"
- Choose "Start in production mode" (we'll deploy rules later)
- Select your Cloud Firestore location:
- Choose closest to your users
- Note: Location can't be changed later!
- Click "Enable"
- In sidebar, click "Storage"
- Click "Get started"
- Keep default security rules
- Use same location as Firestore
- Click "Done"
Copy the example file:
cp .env.example .envOn Windows:
copy .env.example .envOpen .env file and add your Firebase configuration:
VITE_FIREBASE_API_KEY=AIzaSyXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
VITE_FIREBASE_AUTH_DOMAIN=my-app-12345.firebaseapp.com
VITE_FIREBASE_PROJECT_ID=my-app-12345
VITE_FIREBASE_STORAGE_BUCKET=my-app-12345.appspot.com
VITE_FIREBASE_MESSAGING_SENDER_ID=123456789012
VITE_FIREBASE_APP_ID=1:123456789012:web:abcdef123456Important:
- All variables must start with
VITE_prefix - Do NOT commit
.envfile (it's in.gitignore) - Never share your
.envfile publicly
Edit .firebaserc file:
{
"projects": {
"default": "my-app-12345"
}
}Replace my-app-12345 with your actual Firebase project ID.
npm run devYou should see:
VITE v5.x.x ready in XXX ms
β Local: http://localhost:5173/
β Network: use --host to expose
Open http://localhost:5173 in your browser.
You should see the template homepage with:
Firebase React Template
Get started by editing src/App.jsx
- Open
src/App.jsxin your editor - Change the text
- Save the file
- Browser should update automatically without refresh
Create a test file src/firebase/test.js:
import { auth, db } from './config';
console.log('Firebase Auth:', auth);
console.log('Firebase Firestore:', db);Import it in src/main.jsx:
import './firebase/test';Check browser console - you should see Firebase objects logged.
Add to src/firebase/test.js:
import { collection, addDoc } from 'firebase/firestore';
// Test write to Firestore
const testFirestore = async () => {
try {
const docRef = await addDoc(collection(db, 'test'), {
message: 'Hello Firebase!',
timestamp: new Date()
});
console.log('Document written with ID:', docRef.id);
} catch (error) {
console.error('Error adding document:', error);
}
};
testFirestore();Check Firebase Console β Firestore Database - you should see a test collection.
- Check your
VITE_FIREBASE_API_KEYin.env - Make sure it starts with
AIza - Verify it matches Firebase Console
- Run
npm installagain - Delete
node_modulesandpackage-lock.json, then reinstall - Check Node.js version:
node --version(should be 18+)
- Make sure variables start with
VITE_prefix - Restart dev server after changing
.env - Use
import.meta.env.VITE_FIREBASE_API_KEYto access values
- Check
firestore.rulesfile - Make sure authentication is enabled
- Verify you're signed in when testing authenticated features
β Setup Complete! Now you can:
- Configure Firebase - Set up security rules and advanced features
- Understand Project Structure - Learn the codebase organization
- Start Development - Build your application
- Deploy Your App - Go live with Firebase Hosting
- π Report Issues
- π¬ Ask Questions
- π Firebase Docs
- π React Docs
Firebase React Template | Made with β€οΈ | GitHub | Report Issues
Getting Started
Configuration
Advanced Topics
Deployment
- React 19
- Vite
- Firebase 12
- Redux Toolkit
- React Router