A Next.js application demonstrating Firebase Cloud Messaging (FCM) push notifications with browser-based configuration.
- β Browser-based Firebase Configuration - Configure Firebase settings directly from the browser UI
- β Firebase v10+ Support - Uses the latest Firebase modular SDK
- β Next.js 14 - Upgraded to the latest Next.js version
- β Push Notifications - Receive and display push notifications from Firebase Console
- β Service Worker Support - Background notifications even when the app is closed
- β Token Management - Easy FCM token copying for testing
First, install the dependencies:
npm install
# or
yarn installnpm run dev
# or
yarn devOpen http://localhost:3000 with your browser to see the result.
- Go to Firebase Console
- Create a new project or select an existing one
- Navigate to Project Settings β General tab
- Scroll down to Your apps section
- Click on the Web app icon (</>) to add a web app if you haven't already
- Copy the Firebase configuration values:
- API Key
- Auth Domain
- Project ID
- Storage Bucket
- Messaging Sender ID
- App ID
- Measurement ID (optional)
- In Firebase Console, go to Project Settings β Cloud Messaging tab
- Scroll down to Web Push certificates section
- If no key exists, click Generate key pair
- Copy the Key pair value (this is your VAPID key)
- Navigate to the Settings page (
/settings) in the app - Fill in all the Firebase configuration fields
- Click Save Configuration
- The app will reload and initialize Firebase with your configuration
- After configuring Firebase, copy your FCM token from the home page
- Go to Firebase Console β Cloud Messaging
- Click Send test message
- Paste your FCM token in the FCM registration token field
- Enter a notification title and message
- Click Test
- You should receive the notification in your browser!
You can also send notifications programmatically using the Firebase Admin SDK from your backend.
βββ components/
β βββ FirebaseConfigForm.js # Firebase configuration form component
β βββ PushNotificationLayout.js # Push notification handler wrapper
βββ pages/
β βββ index.js # Home page
β βββ settings.js # Firebase configuration page
β βββ offers.js # Example page with notifications
β βββ _app.js # App wrapper
βββ public/
β βββ firebase-messaging-sw.js # Service worker for background notifications
βββ utils/
β βββ firebase.js # Firebase initialization utilities
βββ next.config.js # Next.js configuration
- Next.js 14 - React framework
- Firebase 10.7+ - Firebase Cloud Messaging
- React Toastify - Toast notifications
- LocalForage - Local storage for configuration and tokens
- next-offline - Service worker support
This app requires a browser that supports:
- Service Workers
- Push Notifications API
- IndexedDB (for LocalForage)
Modern browsers (Chrome, Firefox, Edge, Safari 16+) are supported.
- Make sure you've granted notification permissions in your browser
- Verify your Firebase configuration is correct
- Check that your VAPID key is correct
- Ensure the service worker is registered (check browser DevTools β Application β Service Workers)
- Check the browser console for any errors
- Make sure you're accessing the app via HTTPS (or localhost for development)
- Clear your browser cache and reload
- Check browser DevTools β Application β Service Workers for errors
MIT