kreait / laravel-firebase

A Laravel package for the Firebase PHP Admin SDK
https://github.com/kreait/firebase-php
MIT License
995 stars 161 forks source link

Unable to create the messaging service #65

Closed jernejbeg closed 1 year ago

jernejbeg commented 3 years ago

Hi, I am getting the following runtime exception when I do a composer install:

Unable to create the messaging service without a project ID at vendor/kreait/firebase-php/src/Firebase/Factory.php:467

 public function createMessaging(): Messaging
 {
      if (!($projectId = $this->getProjectId())) {
             throw new RuntimeException('Unable to create the messaging service without a project ID');
  }

$messagingApiClient = new Messaging\ApiClient(

$this->createApiClient([

+33 vendor frames

I am using dependency injection in my service class and I have the config set up properly in my env file.

This happens every time I try to do a composer install on other machines (the initial setup went fine). If I remove the code, do a composer install it passes and installs the packages as expected. What could I be doing wrong?

jeromegamez commented 3 years ago

Sorry for the late reply! I haven't encountered this error so far, especially not during a composer install. I just tried this myself with a fresh install and unfortunately wasn't able to reproduce the problem.

In the meantime, version 3.0 of the package was released, could you please check if the problem exists with it as well (unless you're already using it).

The only thing I could guess at the moment is that the FIREBASE_CREDENTIALS is set with an empty value (e.g. with FIREBASE_CREDENTIALS= in the .env file) and that the SDK is instantiated before being available. 🤔

jernejbeg commented 3 years ago

@jeromegamez no problem at all. Maybe you can try the following... create a fresh project and make two branches. The first one can be a plain Laravel installation. After that make a new branch and install the plugin (also make a dummy service). Then switch back to the plain Laravel branch and do a composer install. In this case, the installation should fail and produce a reported problem.

I managed to solve this issue by manually deleting the cache in both the bootstrap and storage directories. Hope we can find where the issue comes from.

qazny commented 3 years ago

Hi, I also experienced this issue. Reason may be that when config was cached, application does not have access to env variables directly (as far as I understand). In this case, script cannot get the path to the file from env. I solved this problem by adding $factory = $factory->withServiceAccount(config('firebase.projects.app.credentials.file'));. Script should also try to get path to credentials from config in Firebase/Factory@getServiceAccount.