Closed JamesPJ closed 1 year ago
Thank you for providing details for the issue, much appreciated (many don't do it 😅).
When you commented to that other issue, I didn't know that this problem with occurred in the context of/while using the FCM notification channel package.
Unfortunately, I'm not familiar with the package and it's not in scope of my package. Using multiple projects "vanilla-style" with my package should work, but I don't know why it doesn't with the other package. I believe you should open an issue on their package instead.
What I did notice is that you're using the same FIREBASE_CREDENTIALS
and other environment variable for both project configurations, could that be the reason?
@jeromegamez Thank you for taking time to look into it.
As I have multiple domains using same codebase, each domain use dedicated .env file.
For Example: If I've configured www.example.com
so the env file would be .env.www.example.com
.
So, I've different domains using different firebase projects.
I did tried logging the firebase config
values to the log to see whether it is has the correct values. Unfortunately, I'm seeing correct values.
As of now, I'm suspecting the service provider, as it is using the singleton
instance. However, I do not have enough info to support my hypothesis.
$this->app->singleton(Firebase\Contract\Messaging::class, static fn (Container $app) => $app->make(FirebaseProjectManager::class)->project()->messaging());
Thank you for the additional insights!
You're right - if you type-hint the Messaging
interface, it will (should) inject the messaging component of the default project defined in the firebase.default
config.
Just to be sure, are you setting the FIREBASE_PROJECT
environment variable differently on each host, in your example to myprojectOne
?
Just to be sure, are you setting the FIREBASE_PROJECT environment variable differently on each host, in your example to myprojectOne?
Yes, Correct. It is different.
Firebase has app limit between 30-50. So, to avoid the limit. I've different projects set for different host.
To be clear. .env.example.com
may have FIREBASE_PROJECT= myprojectOne
and .env.newhost.com
may have FIREBASE_PROJECT= myproject
.
@jeromegamez Any suggestion on this?
I just tested this in a fresh Laravel 8 project with version 4.2 of this package (please note, I don't support versions older than the current one, but I haven't added a supported versions matrix to the README yet, so here we are 😅)
To make my manual tests simple, I have this config/firebase.php
file - in order to test that the correct project is picked up, we can get a database reference and show its URL (at this point, no request is executed, but we can see if the correct FIREBASE_DATABASE_URL
is picked up.
I noticed that, in the config you provided, the database URL is
<?php
return [
'default' => env('FIREBASE_PROJECT', 'myproject'),
'projects' => [
'myproject' => [
'credentials' => [
'file' => env('FIREBASE_CREDENTIALS', 'config/myproject.json'),
],
'database' => [
'url' => env('FIREBASE_DATABASE_URL', 'https://myproject.firebaseio.com'),
],
],
'myprojectOne' => [
'credentials' => [
'file' => env('FIREBASE_CREDENTIALS', 'config/myprojectOne.json'),
],
'database' => [
'url' => env('FIREBASE_DATABASE_URL', 'https://myprojectOne.firebaseio.com'),
],
]
],
];
(Note that I have changed the FIREBASE_DATABASE_URL
for myprojectOne
- in your config, both have the same value.)
In a tinker session, we can now test with
> app('firebase.manager')->project()->database()->getReference()->getUri()->__toString()
= "https://myproject.firebaseio.com/"
if the expected Database URI is printed out.
In my tests, it worked with the following setups:
FIREBASE_PROJECT=myproject
" ✅ FIREBASE_PROJECT=myprojectOne
" ✅FIREBASE_PROJECT
not defifined -> myproject
is used ✅Here are my suggestions:
projectOne
), either in a Tinker session or by dump()/dd()
ing it somewhere'default' => env('FIREBASE_PROJECT', 'myproject'),
with 'default' => env('FIREBASE_PROJECT),
- with this, you will get an error if the FIREBASE_PROJECT
environment variable is not set.Long story short: I can't reproduce the problem and must assume that this is caused by something else, probably in the usage of the FCM Notification Channel package.
I mentioned earlier that versions < 5.x are not supported anymore - the laravel-notification-channels/fcm
package has also a newer major release (3.x). Perhaps there is something that doesn't add up. (PHP 8.0.* is EOLed as well)
I hope this helps.
Replace 'default' => env('FIREBASE_PROJECT', 'myproject'), with 'default' => env('FIREBASE_PROJECT), - with this, you will get an error if the FIREBASE_PROJECT environment variable is not set.
This did the trick. It was always reading the default
value instead of the env
value. Not sure why.
Thank you for your help!
Describe the bug
I've 3 projects configured in firebase.php config
But, if I send notification for any project apart from the first one, I'm getting SenderId mismatch error. I've cross checked the issue by moving up and down the projects in the array. I've no idea why it is only taking the first project.
Installed packages
Steps to reproduce the issue.
firebase.php
Error message/Stack trace
Additional information
Application is hosted for multiple domains using https://github.com/gecche/laravel-multidomain