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) }