From 7e75d79dc806124109df2aaef5cae0c2905722c4 Mon Sep 17 00:00:00 2001 From: Yared Yemane Date: Mon, 11 May 2026 11:02:01 -0700 Subject: [PATCH] Pass Firebase project_id explicitly from service account JSON. Parse FCM_SERVICE_ACCOUNT_KEY, validate project_id, and provide firebase.Config{ProjectID} during FCM client initialization to prevent missing-project-id messaging failures. Co-authored-by: Cursor --- internal/services/notification/service.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/internal/services/notification/service.go b/internal/services/notification/service.go index 0dbeb46..30750e3 100644 --- a/internal/services/notification/service.go +++ b/internal/services/notification/service.go @@ -95,12 +95,25 @@ func (s *Service) initFCMClient() error { // Prepare client options; if a service account JSON string is provided, use it. var opts []option.ClientOption + var fbConfig *firebase.Config if s.config.FCMServiceAccountKey != "" { + var sa struct { + ProjectID string `json:"project_id"` + } + if err := json.Unmarshal([]byte(s.config.FCMServiceAccountKey), &sa); err != nil { + return fmt.Errorf("invalid FCM_SERVICE_ACCOUNT_KEY JSON: %w", err) + } + if strings.TrimSpace(sa.ProjectID) == "" { + return fmt.Errorf("FCM_SERVICE_ACCOUNT_KEY is missing project_id") + } + fbConfig = &firebase.Config{ + ProjectID: strings.TrimSpace(sa.ProjectID), + } opts = append(opts, option.WithCredentialsJSON([]byte(s.config.FCMServiceAccountKey))) } // Initialize Firebase app - app, err := firebase.NewApp(ctx, nil, opts...) + app, err := firebase.NewApp(ctx, fbConfig, opts...) if err != nil { return fmt.Errorf("failed to initialize Firebase app: %w", err) }