A production-ready React authentication system built with Firebase β featuring email/password sign-in, Google OAuth, password reset, and a post-login dashboard.
-
Email & Password Authentication
- Sign up & sign in
- Validation & error handling
- Firebase auth integration
-
Google OAuth
- One-click Google popup login
-
Password Reset
- Sends password reset email
-
Password Strength Meter
- Real-time password feedback
-
Auth Persistence
- User session survives refresh using
onAuthStateChanged
- User session survives refresh using
-
Dashboard
- Shows:
- UID
- Provider
- Verification status
- Shows:
-
Firestore Ready
dbalready exported from Firebase config
| Layer | Technology |
|---|---|
| Frontend | React 18 |
| Authentication | Firebase Auth |
| Database | Cloud Firestore |
| Hosting | Firebase Hosting |
| Bundler | Vite |
firebase-auth/
βββ FirebaseAuth.jsx
βββ firebase/
β βββ config.js
βββ hooks/
β βββ useAuth.js
βββ utils/
β βββ helpers.js
βββ styles/
β βββ authStyles.js
βββ components/
β βββ Dashboard.jsx
β βββ Toast.jsx
β βββ StrengthBar.jsx
β βββ Logo.jsx
β βββ GoogleIcon.jsx
β βββ Divider.jsx
βββ views/
βββ LoginView.jsx
βββ SignupView.jsx
βββ ResetView.jsxgit clone : https://github.com/pratikshajadhav08/react-firebase-authentication
cd firebase-authnpm installCreate a Firebase project from:
π https://console.firebase.google.com
Go to:
Project Settings β Your Apps β SDK Setup
Replace config inside:
firebase/config.jsWith:
const firebaseConfig = {
apiKey: "YOUR_API_KEY",
authDomain: "YOUR_PROJECT_ID.firebaseapp.com",
projectId: "YOUR_PROJECT_ID",
storageBucket: "YOUR_PROJECT_ID.appspot.com",
messagingSenderId: "YOUR_SENDER_ID",
appId: "YOUR_APP_ID",
};Inside Firebase Console:
Authentication β Sign-in Method
Enable:
- β Email/Password
- β Google
npm run devApp runs at:
http://localhost:5173npm run buildnpm install -g firebase-toolsfirebase loginfirebase init hostingfirebase deploy --only hosting| Prompt | Answer |
|---|---|
| Which project? | Your Firebase Project ID |
| Public directory? | dist |
| Configure as SPA? | Yes |
| Overwrite index.html? | No |
import { db } from "./firebase/config";
import { collection, addDoc } from "firebase/firestore";
await addDoc(collection(db, "users"), {
uid: user.uid,
email: user.email,
createdAt: new Date(),
});Create a .env file:
VITE_API_KEY=your_api_key
VITE_AUTH_DOMAIN=your_project.firebaseapp.com
VITE_PROJECT_ID=your_project_id
VITE_STORAGE_BUCKET=your_project.appspot.com
VITE_MESSAGING_SENDER_ID=your_sender_id
VITE_APP_ID=your_app_idUpdate firebase/config.js:
const firebaseConfig = {
apiKey: import.meta.env.VITE_API_KEY,
authDomain: import.meta.env.VITE_AUTH_DOMAIN,
projectId: import.meta.env.VITE_PROJECT_ID,
storageBucket: import.meta.env.VITE_STORAGE_BUCKET,
messagingSenderId: import.meta.env.VITE_MESSAGING_SENDER_ID,
appId: import.meta.env.VITE_APP_ID,
};Add .env to .gitignore
echo ".env" >> .gitignoreLive at: https://react-firebase-authentication-two.vercel.app/
- Protected Routes
- Role-Based Auth
- Dark Mode
- Email Verification
- MFA Authentication
- GitHub OAuth
- User Profiles
- Admin Dashboard
-
Firebase Docs
https://firebase.google.com/docs -
React Docs
https://react.dev -
Vite Docs
https://vitejs.dev
MIT License