fix: FCM push not sending — add v1 API + better diagnostics
- FCMService now supports both HTTP v1 API (service account) and legacy API (server key) - v1 API uses OAuth2 JWT auth with Firebase service account; tries this first - Falls back to legacy HTTP API if only server key is configured - Removes invalid tokens from DB automatically (NotRegistered, INVALID_ARGUMENT, etc.) - AdminController now logs push result status and shows in UI response - .env updated with FCM_SERVER_KEY placeholder and docs - Migration 010 run in dev
This commit is contained in:
@@ -289,14 +289,21 @@ class AdminController
|
||||
]);
|
||||
|
||||
$fcm = new FCMService();
|
||||
$pushResult = '';
|
||||
if ($userId) {
|
||||
$fcm->sendToUser($userId, $title, $message, $type, $noteId);
|
||||
$sent = $fcm->sendToUser($userId, $title, $message, $type, $noteId);
|
||||
$pushResult = $sent ? ' (push sent)' : ($fcm->isConfigured() ? ' (push failed)' : '');
|
||||
} else {
|
||||
$fcm->sendToAll($title, $message, $type, $noteId);
|
||||
$count = $fcm->sendToAll($title, $message, $type, $noteId);
|
||||
$pushResult = $fcm->isConfigured() ? " (push sent to {$count} devices)" : '';
|
||||
}
|
||||
|
||||
$this->auditService->log('notification_sent', 'notification', null, ['title' => $title, 'target' => $userId ? "user #{$userId}" : 'all users']);
|
||||
$this->auditService->log('notification_sent', 'notification', null, [
|
||||
'title' => $title,
|
||||
'target' => $userId ? "user #{$userId}" : 'all users',
|
||||
'push' => $fcm->isConfigured() ? 'sent' : 'not_configured',
|
||||
]);
|
||||
|
||||
$this->view->json(['success' => true, 'message' => 'Notification sent successfully.']);
|
||||
$this->view->json(['success' => true, 'message' => 'Notification sent successfully.' . $pushResult]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user