milliorn
nextjs-firebase-starter
TypeScript

A production-ready starter template for building full-stack web applications with Next.js 15, React 19, and Firebase. This template ships with email/password authentication, Firestore data helpers, a route-protected admin page, and a global auth context so you can skip the boilerplate.

Last updated Aug 6, 2026
158
Stars
36
Forks
0
Issues
0
Stars/day
Attention Score
43
Language breakdown
TypeScript 89.7%
JavaScript 7.5%
CSS 2.8%
โ–ธ Files click to expand
README

Next.js Firebase Starter

A production-ready starter template for building full-stack web applications with Next.js 15, React 19, and Firebase. This template ships with email/password authentication, Firestore data helpers, a route-protected admin page, and a global auth context so you can skip the boilerplate and start building.


Tech Stack

| Layer | Technology | | -------------- | ---------------------------------------------------------------- | | Framework | Next.js 15 (App Router) | | UI Library | React 19 | | Styling | Tailwind CSS | | Language | TypeScript | | Backend / Auth | Firebase (Auth + Firestore) | | Linting | ESLint + Prettier |


Features

  • Email / Password Authentication - sign-up, sign-in, and sign-out flows backed by Firebase Auth
  • Global Auth Context - a React context provider (AuthContextProvider) wraps the app and exposes the current user via useAuthContext()
  • Protected Routes - the /admin route redirects unauthenticated users to the home page
  • Firestore Helpers - typed addData and getData utilities for reading and writing documents
  • App Router - built on the Next.js App Router with server components, layouts, and file-based routing
  • Inter Font - automatically loaded and optimized via next/font/google

Prerequisites


Getting Started

1. Use the template

Click Use this template on GitHub to create your own repository, then clone it:

git clone https://github.com/<your-username>/<your-repo>.git
cd <your-repo>
npm install

2. Configure environment variables

Create a .env.local file in the project root:

cp .env.local.example .env.local   # if the example file exists, otherwise create it

Add your Firebase project credentials (see Set Up Firebase below):

NEXTPUBLICFIREBASEAPIKEY=yourapikey
NEXTPUBLICFIREBASEAUTHDOMAIN=yourauthdomain
NEXTPUBLICFIREBASEPROJECTID=yourprojectid
NEXTPUBLICFIREBASESTORAGEBUCKET=yourstoragebucket
NEXTPUBLICFIREBASEMESSAGINGSENDERID=yourmessagingsenderid
NEXTPUBLICFIREBASEAPPID=yourappid
Important: .env.local is already listed in .gitignore. Never commit real credentials to version control.

3. Run the development server

npm run dev

Open http://localhost:3000 in your browser. The page hot-reloads as you edit files under src/.


Set Up Firebase

  • Go to https://console.firebase.google.com/ and sign in with your Google account.
  • Click Add project, give it a name, and click Create project.
  • On the project overview page, click the web icon (</>) to register a web app.
  • Give the app a nickname and click Register app. Firebase will display your config object. Copy the values into .env.local.
  • In the left sidebar, go to Build > Authentication > Sign-in method and enable Email/Password.
  • (Optional) Go to Build > Firestore Database and create a database to use the Firestore helpers.

Project Structure

src/
โ”œโ”€โ”€ app/                        # Next.js App Router pages and layouts
โ”‚   โ”œโ”€โ”€ admin/
โ”‚   โ”‚   โ””โ”€โ”€ page.tsx            # Protected page, redirects unauthenticated users
โ”‚   โ”œโ”€โ”€ signin/
โ”‚   โ”‚   โ””โ”€โ”€ page.tsx            # Sign-in page
โ”‚   โ”œโ”€โ”€ signup/
โ”‚   โ”‚   โ””โ”€โ”€ page.tsx            # Sign-up page
โ”‚   โ”œโ”€โ”€ globals.css             # Global styles (Tailwind base imports)
โ”‚   โ”œโ”€โ”€ layout.tsx              # Root layout, wraps app in AuthContextProvider
โ”‚   โ””โ”€โ”€ page.tsx                # Home page
โ”‚
โ”œโ”€โ”€ context/
โ”‚   โ””โ”€โ”€ AuthContext.tsx         # Auth context provider and useAuthContext hook
โ”‚
โ””โ”€โ”€ firebase/
    โ”œโ”€โ”€ config.ts               # Firebase app initialization (singleton)
    โ”œโ”€โ”€ auth/
    โ”‚   โ”œโ”€โ”€ signIn.ts           # signInWithEmailAndPassword wrapper
    โ”‚   โ””โ”€โ”€ signup.ts           # createUserWithEmailAndPassword wrapper
    โ””โ”€โ”€ firestore/
        โ”œโ”€โ”€ addData.ts          # setDoc helper with merge support
        โ””โ”€โ”€ getData.js          # getDoc helper

Authentication

Authentication is handled through Firebase Auth and surfaced app-wide via a React context.

src/context/AuthContext.tsx subscribes to onAuthStateChanged and exposes { user } to any component that calls useAuthContext(). The root layout wraps the entire app in this provider, so auth state is always available client-side.

src/firebase/auth/ contains two thin async wrappers:

  • signIn(email, password) - calls signInWithEmailAndPassword and returns { result, error }
  • signup(email, password) - calls createUserWithEmailAndPassword and returns { result, error }
Both functions return a consistent { result, error } shape so callers can handle errors without try/catch.

Protected routes - src/app/admin/page.tsx demonstrates the pattern: read user from useAuthContext() inside a useEffect, then call router.push("/") if the user is null.


Firestore Helpers

Two utility functions live in src/firebase/firestore/:

| Function | Description | | ------------------------------- | -------------------------------------------------------------------------------------- | | addData(collection, id, data) | Writes (or merges) a document at collection/id using setDoc with { merge: true } | | getData(collection, id) | Reads a single document from collection/id using getDoc |

Both return { result, error } for consistent error handling.


Available Scripts

| Command | Description | | ----------------- | ---------------------------------------------------------------- | | npm run dev | Start the development server at http://localhost:3000 | | npm run build | Build the application for production | | npm run start | Start the production server (requires build first) | | npm run lint | Run ESLint across the project | | npm run release | Bump the version and generate a changelog via standard-version |


Deployment

Vercel (recommended)

  • Push your repository to GitHub.
  • Import the project at vercel.com/new.
  • Add all NEXTPUBLICFIREBASE_* environment variables in the Vercel project settings.
  • Deploy. Vercel handles builds and previews automatically on every push.

Other platforms

Set the same NEXTPUBLICFIREBASE_* environment variables in your host's dashboard and run:

npm run build
npm run start

See the Next.js deployment documentation for platform-specific guidance.


Contributing

Contributions are welcome. Please read CONTRIBUTING.md before opening a pull request. Bug reports and feature requests can be filed via GitHub Issues.

Security

Please review SECURITY.md for the project's vulnerability disclosure policy.

License

This project is licensed under the MIT License. See LICENSE for details.


Resources

ยฉ 2026 GitRepoTrend ยท milliorn/nextjs-firebase-starter ยท Updated daily from GitHub