## Phase 1: Critical Feature Completion (Beacon Voting) - Add VouchBeacon, ReportBeacon, RemoveBeaconVote methods to PostRepository - Implement beacon voting HTTP handlers with confidence score calculations - Register new beacon routes: /beacons/:id/vouch, /beacons/:id/report, /beacons/:id/vouch (DELETE) - Auto-flag beacons at 5+ reports, confidence scoring (0.5 base + 0.1 per vouch) ## Phase 2: Feed Logic & Post Distribution Integrity - Verify unified feed logic supports all content types (Standard, Quips, Beacons) - Ensure proper distribution: Profile Feed + Main/Home Feed for followers - Beacon Map integration for location-based content - Video content filtering for Quips feed ## Phase 3: The Notification System - Create comprehensive NotificationService with FCM integration - Add CreateNotification method to NotificationRepository - Implement smart deep linking: beacon_map, quip_feed, main_feed - Trigger notifications for beacon interactions and cross-post comments - Push notification logic with proper content type detection ## Phase 4: The Great Supabase Purge - Delete function_proxy.go and remove /functions/:name route - Remove SupabaseURL, SupabaseKey from config.go - Remove SupabaseID field from User model - Clean all Supabase imports and dependencies - Sanitize codebase of legacy Supabase references ## Phase 5: Flutter Frontend Integration - Implement vouchBeacon(), reportBeacon(), removeBeaconVote() in ApiService - Replace TODO delay in video_comments_sheet.dart with actual publishComment call - Fix compilation errors (named parameters, orphaned child properties) - Complete frontend integration with Go API endpoints ## Additional Improvements - Fix compilation errors in threaded_comment_widget.dart (orphaned child property) - Update video_comments_sheet.dart to use proper named parameters - Comprehensive error handling and validation - Production-ready notification system with deep linking ## Migration Status: 100% Complete - Backend: Fully migrated from Supabase to custom Go/Gin API - Frontend: Integrated with new Go endpoints - Notifications: Complete FCM integration with smart routing - Database: Clean of all Supabase dependencies - Features: All functionality preserved and enhanced Ready for VPS deployment and production testing!
335 lines
8.6 KiB
Markdown
335 lines
8.6 KiB
Markdown
# FCM Notifications - Complete Deployment Guide
|
|
|
|
## Quick Start (TL;DR)
|
|
|
|
1. Get VAPID key from Firebase Console
|
|
2. Download Firebase service account JSON
|
|
3. Update Flutter app with VAPID key
|
|
4. Upload JSON to server at `/opt/sojorn/firebase-service-account.json`
|
|
5. Add to `/opt/sojorn/.env`: `FIREBASE_CREDENTIALS_FILE=/opt/sojorn/firebase-service-account.json`
|
|
6. Restart Go backend
|
|
7. Test notifications
|
|
|
|
---
|
|
|
|
## Detailed Steps
|
|
|
|
### 1. Get Firebase Credentials
|
|
|
|
#### A. Get VAPID Key (for Web Push)
|
|
|
|
1. Go to https://console.firebase.google.com/project/sojorn-a7a78/settings/cloudmessaging
|
|
2. Scroll to **Web configuration** section
|
|
3. Under **Web Push certificates**, copy the **Key pair**
|
|
4. It should look like: `BNxS7_very_long_string_of_characters...`
|
|
|
|
#### B. Download Service Account JSON (for Server)
|
|
|
|
1. Go to https://console.firebase.google.com/project/sojorn-a7a78/settings/serviceaccounts
|
|
2. Click **Generate new private key**
|
|
3. Click **Generate key** - downloads JSON file
|
|
4. Save it somewhere safe (you'll upload it to server)
|
|
|
|
---
|
|
|
|
### 2. Update Flutter App with VAPID Key
|
|
|
|
**File:** `sojorn_app/lib/config/firebase_web_config.dart`
|
|
|
|
Replace line 24:
|
|
```dart
|
|
static const String _vapidKey = 'YOUR_VAPID_KEY_HERE';
|
|
```
|
|
|
|
With your actual VAPID key:
|
|
```dart
|
|
static const String _vapidKey = 'BNxS7_your_actual_vapid_key_from_firebase_console';
|
|
```
|
|
|
|
**Commit and push:**
|
|
```bash
|
|
cd c:\Webs\Sojorn
|
|
git add sojorn_app/lib/config/firebase_web_config.dart
|
|
git commit -m "Add FCM VAPID key for web push notifications"
|
|
git push
|
|
```
|
|
|
|
---
|
|
|
|
### 3. Upload Firebase Service Account JSON to Server
|
|
|
|
**From Windows PowerShell:**
|
|
```powershell
|
|
scp -i "C:\Users\Patrick\.ssh\mpls.pem" "C:\path\to\sojorn-a7a78-firebase-adminsdk-xxxxx.json" patrick@194.238.28.122:/tmp/firebase-service-account.json
|
|
```
|
|
|
|
Replace `C:\path\to\...` with the actual path to your downloaded JSON file.
|
|
|
|
---
|
|
|
|
### 4. Configure Server
|
|
|
|
**SSH to server:**
|
|
```bash
|
|
ssh -i "C:\Users\Patrick\.ssh\mpls.pem" patrick@194.238.28.122
|
|
```
|
|
|
|
**Run the setup script:**
|
|
```bash
|
|
cd /home/patrick
|
|
curl -O https://raw.githubusercontent.com/your-repo/sojorn/main/setup_fcm_server.sh
|
|
chmod +x setup_fcm_server.sh
|
|
./setup_fcm_server.sh
|
|
```
|
|
|
|
**Or manually:**
|
|
|
|
```bash
|
|
# Move JSON file
|
|
sudo mv /tmp/firebase-service-account.json /opt/sojorn/firebase-service-account.json
|
|
sudo chmod 600 /opt/sojorn/firebase-service-account.json
|
|
sudo chown patrick:patrick /opt/sojorn/firebase-service-account.json
|
|
|
|
# Edit .env
|
|
sudo nano /opt/sojorn/.env
|
|
```
|
|
|
|
Add these lines to `.env`:
|
|
```bash
|
|
# Firebase Cloud Messaging
|
|
FIREBASE_CREDENTIALS_FILE=/opt/sojorn/firebase-service-account.json
|
|
FIREBASE_WEB_VAPID_KEY=BNxS7_your_actual_vapid_key_here
|
|
```
|
|
|
|
Save and exit (Ctrl+X, Y, Enter)
|
|
|
|
---
|
|
|
|
### 5. Restart Go Backend
|
|
|
|
```bash
|
|
cd /home/patrick/sojorn-backend
|
|
sudo systemctl restart sojorn-api
|
|
sudo systemctl status sojorn-api
|
|
```
|
|
|
|
**Check logs for successful initialization:**
|
|
```bash
|
|
sudo journalctl -u sojorn-api -f --since "1 minute ago"
|
|
```
|
|
|
|
Look for:
|
|
```
|
|
[INFO] PushService initialized successfully
|
|
```
|
|
|
|
If you see errors, check:
|
|
- JSON file exists: `ls -la /opt/sojorn/firebase-service-account.json`
|
|
- .env has correct path: `sudo cat /opt/sojorn/.env | grep FIREBASE`
|
|
- JSON is valid: `cat /opt/sojorn/firebase-service-account.json | jq .`
|
|
|
|
---
|
|
|
|
### 6. Deploy Flutter App
|
|
|
|
**Hot restart (no build needed):**
|
|
Just refresh your browser or press `R` in the Flutter dev console.
|
|
|
|
**Or rebuild and deploy:**
|
|
```bash
|
|
cd c:\Webs\Sojorn\sojorn_app
|
|
flutter build web --release
|
|
# Deploy to your hosting
|
|
```
|
|
|
|
---
|
|
|
|
### 7. Test FCM Notifications
|
|
|
|
#### Test 1: Check Token Registration
|
|
|
|
1. Open Sojorn web app in browser
|
|
2. Open DevTools (F12) > Console
|
|
3. Look for: `FCM token registered (web): d2n2ELGKel7yzPL3wZLGSe...`
|
|
4. If you see "Web push is missing FIREBASE_WEB_VAPID_KEY", VAPID key is not set correctly
|
|
|
|
#### Test 2: Check Database
|
|
|
|
```bash
|
|
sudo -u postgres psql sojorn
|
|
```
|
|
|
|
```sql
|
|
-- Check FCM tokens are being stored
|
|
SELECT user_id, platform, LEFT(fcm_token, 30) as token_preview, created_at
|
|
FROM public.fcm_tokens
|
|
ORDER BY created_at DESC
|
|
LIMIT 5;
|
|
```
|
|
|
|
Expected output:
|
|
```
|
|
user_id | platform | token_preview | created_at
|
|
-------------------------------------+----------+--------------------------------+-------------------
|
|
5568b545-5215-4734-875f-84b3106cd170 | web | d2n2ELGKel7yzPL3wZLGSe:APA91b | 2026-01-29 05:50
|
|
```
|
|
|
|
#### Test 3: Send Test Message
|
|
|
|
1. Open two browser windows (or use two different users)
|
|
2. User A sends a chat message to User B
|
|
3. User B should receive a push notification (if browser is in background)
|
|
|
|
**Check server logs:**
|
|
```bash
|
|
sudo journalctl -u sojorn-api -f | grep -i push
|
|
```
|
|
|
|
You should see:
|
|
```
|
|
[INFO] Sending push notification to user 5568b545...
|
|
[INFO] Push notification sent successfully
|
|
```
|
|
|
|
---
|
|
|
|
## Troubleshooting
|
|
|
|
### Issue: "Web push is missing FIREBASE_WEB_VAPID_KEY"
|
|
|
|
**Cause:** VAPID key not set in Flutter app
|
|
|
|
**Fix:**
|
|
1. Update `firebase_web_config.dart` with actual VAPID key
|
|
2. Hot restart Flutter app
|
|
3. Check console again
|
|
|
|
### Issue: "Failed to initialize PushService"
|
|
|
|
**Cause:** Firebase service account JSON not found or invalid
|
|
|
|
**Fix:**
|
|
```bash
|
|
# Check file exists
|
|
ls -la /opt/sojorn/firebase-service-account.json
|
|
|
|
# Check .env has correct path
|
|
sudo cat /opt/sojorn/.env | grep FIREBASE_CREDENTIALS_FILE
|
|
|
|
# Validate JSON
|
|
cat /opt/sojorn/firebase-service-account.json | jq .
|
|
|
|
# Check permissions
|
|
ls -la /opt/sojorn/firebase-service-account.json
|
|
# Should show: -rw------- 1 patrick patrick
|
|
```
|
|
|
|
### Issue: Notifications not received
|
|
|
|
**Checklist:**
|
|
- [ ] Browser notification permissions granted
|
|
- [ ] FCM token registered (check console)
|
|
- [ ] Token stored in database (check SQL)
|
|
- [ ] Go backend logs show push being sent
|
|
- [ ] Service worker registered (check DevTools > Application > Service Workers)
|
|
|
|
**Check service worker:**
|
|
1. Open DevTools > Application > Service Workers
|
|
2. Should see `firebase-messaging-sw.js` registered
|
|
3. If not, check `sojorn_app/web/firebase-messaging-sw.js` exists
|
|
|
|
---
|
|
|
|
## Current Configuration
|
|
|
|
**Firebase Project:**
|
|
- Project ID: `sojorn-a7a78`
|
|
- Sender ID: `486753572104`
|
|
- Console: https://console.firebase.google.com/project/sojorn-a7a78
|
|
|
|
**Server Paths:**
|
|
- .env: `/opt/sojorn/.env`
|
|
- Service Account: `/opt/sojorn/firebase-service-account.json`
|
|
- Backend: `/home/patrick/sojorn-backend`
|
|
|
|
**Flutter Files:**
|
|
- Config: `sojorn_app/lib/config/firebase_web_config.dart`
|
|
- Service Worker: `sojorn_app/web/firebase-messaging-sw.js`
|
|
- Notification Service: `sojorn_app/lib/services/notification_service.dart`
|
|
|
|
---
|
|
|
|
## How FCM Works in Sojorn
|
|
|
|
1. **User opens app** → Flutter requests notification permission
|
|
2. **Permission granted** → Firebase generates FCM token
|
|
3. **Token sent to backend** → Stored in `fcm_tokens` table
|
|
4. **Event occurs** (new message, follow, etc.) → Go backend calls `PushService.SendPush()`
|
|
5. **FCM sends notification** → User's device/browser receives it
|
|
6. **User clicks notification** → App opens to relevant screen
|
|
|
|
**Notification Triggers:**
|
|
- New chat message (`chat_handler.go:156`)
|
|
- New follower (`user_handler.go:141`)
|
|
- Follow request accepted (`user_handler.go:319`)
|
|
|
|
---
|
|
|
|
## Quick Reference Commands
|
|
|
|
```bash
|
|
# SSH to server
|
|
ssh -i "C:\Users\Patrick\.ssh\mpls.pem" patrick@194.238.28.122
|
|
|
|
# Check .env
|
|
sudo cat /opt/sojorn/.env | grep FIREBASE
|
|
|
|
# Check service account file
|
|
ls -la /opt/sojorn/firebase-service-account.json
|
|
cat /opt/sojorn/firebase-service-account.json | jq .project_id
|
|
|
|
# Restart backend
|
|
sudo systemctl restart sojorn-api
|
|
|
|
# View logs
|
|
sudo journalctl -u sojorn-api -f
|
|
|
|
# Check FCM tokens in DB
|
|
sudo -u postgres psql sojorn -c "SELECT COUNT(*) as token_count FROM public.fcm_tokens;"
|
|
|
|
# View recent tokens
|
|
sudo -u postgres psql sojorn -c "SELECT user_id, platform, created_at FROM public.fcm_tokens ORDER BY created_at DESC LIMIT 5;"
|
|
```
|
|
|
|
---
|
|
|
|
## Files Modified
|
|
|
|
1. `sojorn_app/lib/config/firebase_web_config.dart` - Added VAPID key placeholder
|
|
2. `go-backend/.env.example` - Updated FCM configuration format
|
|
3. Created `FCM_SETUP_GUIDE.md` - Detailed setup instructions
|
|
4. Created `setup_fcm_server.sh` - Automated server setup script
|
|
|
|
---
|
|
|
|
## Next Steps After Deployment
|
|
|
|
1. Monitor logs for FCM errors
|
|
2. Test notifications with real users
|
|
3. Check FCM token count grows as users log in
|
|
4. Verify push notifications work on:
|
|
- Chrome (desktop & mobile)
|
|
- Firefox (desktop & mobile)
|
|
- Safari (if supported)
|
|
- Edge
|
|
|
|
---
|
|
|
|
## Support
|
|
|
|
If you encounter issues:
|
|
1. Check logs: `sudo journalctl -u sojorn-api -f`
|
|
2. Verify configuration: `sudo cat /opt/sojorn/.env | grep FIREBASE`
|
|
3. Test JSON validity: `cat /opt/sojorn/firebase-service-account.json | jq .`
|
|
4. Check Firebase Console for errors: https://console.firebase.google.com/project/sojorn-a7a78/notification
|