3.2 KiB
3.2 KiB
Notifications Troubleshooting (Go Backend)
Note
: This document has been updated for the 100% Go backend migration. Legacy Supabase edge function references are no longer applicable.
Current Architecture
All notification APIs now use the Go backend with JWT authentication:
- Register Token:
POST /api/v1/notifications/device - Unregister Token:
DELETE /api/v1/notifications/device - Get Notifications:
GET /api/v1/notifications
Authentication uses Authorization: Bearer <token> header with Go-issued JWTs.
Common Issues
1. Token Not Syncing to Backend
Symptoms:
- FCM token obtained successfully but not stored in database
- Debug logs show
[FCM] Token synced with Go Backend successfullynot appearing
Solutions:
- Verify user is authenticated before calling
NotificationService.init() - Check API endpoint responds (network tab / logs)
- Ensure JWT token is valid and not expired
2. Push Notifications Not Received
Symptoms:
- Token exists in database
- No push received on device
Diagnosis:
-- Check if token exists for user
SELECT * FROM user_fcm_tokens WHERE user_id = 'your-uuid';
Solutions:
- Verify
FIREBASE_CREDENTIALS_FILEpath is correct in backend.env - Check Firebase Console for delivery reports
- For web, verify
FIREBASE_WEB_VAPID_KEYmatches Firebase Console - On Android 13+, check
POST_NOTIFICATIONSpermission granted
3. Android 13+ Permission Denied
Symptoms:
[FCM] Android notification permission not granted: denied
Solution:
The app now properly requests POST_NOTIFICATIONS at runtime. If user denied:
- Guide them to Settings > Apps > Sojorn > Notifications
- Enable notifications manually
4. Web Push Not Working
Symptoms:
- Token is null on web platform
[FCM] Web push is missing FIREBASE_WEB_VAPID_KEY
Solutions:
- Verify VAPID key in
lib/config/firebase_web_config.dart - Key must match Firebase Console > Cloud Messaging > Web Push certificates
- Must be served over HTTPS (except localhost)
5. Duplicate Tokens in Database
The schema now has a unique constraint on (user_id, token):
UNIQUE(user_id, token)
This prevents duplicates via upsert logic:
ON CONFLICT (user_id, token) DO UPDATE SET last_updated = ...
Logout Cleanup
On logout, the Flutter client now:
- Calls backend to delete token from
user_fcm_tokens - Deletes token from Firebase locally via
deleteToken() - Resets initialization state
This ensures the device no longer receives notifications for the logged-out user.
Testing Checklist
- Token registration works on Android
- Token registration works on Web
- Token appears in
user_fcm_tokenstable with correctdevice_type - New message triggers push to recipient
- Post save triggers push to author
- Comment triggers push to post author
- Follow triggers push to followed user
- Tapping notification navigates correctly
- Logout removes token from database
- Re-login registers new token
Related Documentation
- FCM Implementation Guide - Complete implementation details
- Backend API Documentation - All API endpoints