Firebase Tutorial
- Home
- Introduction
- Project Setup
- Authentication (Email/Pass)
- Social Authentication
- Cloud Firestore (Basics)
- Firestore Queries
- Real-time Updates
- Firestore Security Rules
- Cloud Storage
- Storage Security Rules
- Cloud Functions (Intro)
- Triggering Functions
- Firebase Hosting
- Firebase Analytics
- Crashlytics & Performance
- Remote Config
- App Check
- Offline Persistence
- Firebase with Next.js
- Best Practices
Firebase Project Setup
Setting up Firebase is a simple three-step process: Create a project, register your app, and install the SDK.
1. Create a Firebase Project
- Go to the Firebase Console.
- Click "Add Project" and enter a name.
- (Optional) Enable Google Analytics for your project.
- Click "Create Project".
2. Register Your App
Firebase supports multiple platforms. For this tutorial, we focus on Web.
- In the center of the project overview page, click the Web icon (</>).
- Enter an app nickname and click "Register app".
- You will see your firebaseConfig object. Copy this; you'll need it soon.
3. Install Firebase SDK
In your Next.js project directory, run the following command:
npm install firebase4. Initialize Firebase
Create a file named lib/firebase.js to initialize the app:
import { initializeApp } from "firebase/app";
import { getFirestore } from "firebase/firestore";
import { getAuth } from "firebase/auth";
const firebaseConfig = {
apiKey: "YOUR_API_KEY",
authDomain: "YOUR_AUTH_DOMAIN",
projectId: "YOUR_PROJECT_ID",
storageBucket: "YOUR_STORAGE_BUCKET",
messagingSenderId: "YOUR_SENDER_ID",
appId: "YOUR_APP_ID"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
// Initialize Services
export const db = getFirestore(app);
export const auth = getAuth(app);
export default app;Security Tip: Never check your `apiKey` into a public version control system. Use Environment Variables `.env.local` instead.