I have a React App hosted on Firebase Hosting that retrieves environment configuration values via a call to a Firebase Function (an impl recommended here). Here is the implementation of the function:
const functions = require('firebase-functions');
module.exports = functions.https.onRequest((req, res) => {
res.status(200).send(functions.config());
});
From the Firebase CLI, when I call:
firebase functions:config:get
I see:
{
"auth": {
"clientid": MY_CLIENT_ID,
"signoutreturnto": SOME_URL,
"responsetype": SOME_URL,
"redirecturi": SOME_OTHER_URL,
"scope": SOME_OTHER_STRING,
"domain": SOME_DOMAIN
}
}
calling "Firebase deploy --only functions" from the Firebase CLI yields a URL endpoint to invoke the deployed firebase function, config, which returns my environmental config:
https://us-central1-MY_FIREBASE_APP.cloudfunctions.net/config
Invoking this endpoint returns the expected JSON representing my configuration + that appended by Firebase:
{
"auth": {
"clientid": MY_CLIENT_ID,
"signoutreturnto": SOME_URL,
"responsetype": SOME_URL,
"redirecturi": SOME_OTHER_URL,
"scope": SOME_OTHER_STRING,
"domain": SOME_DOMAIN
},
"firebase": {
"databaseURL": MY_DATABASE_URL,
"storageBucket": MY_STORAGE_BUCKET,
"apiKey": MY_API_KEY,
"authDomain": MY_AUTH_DOMAIN,
"projectId": MY_PROJECT_ID,
"credential": {
"credential_": {}
}
}
}
I have edited my firebase.json with re-write rules to serve my functions as API endpoints
{
"hosting": {
"public": "build",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
},
{
"source": "/config", "function": "config"
}
]
}
}
However - when I serve the functions locally using the following command from the Firebase CLI:
Firebase serve --only functions,hosting
and I invoke the generated, local endpoint for my config function:
http://localhost:5001/MY_FIREBASE_APP/us-central1/config
The returned json object is missing the expected "auth" object (seen above). Instead, the JSON returned is:
{
"firebase": {
"databaseURL": MY_DATABASE_URL,
"storageBucket": MY_STORAGE_BUCKET,
"apiKey": MY_API_KEY,
"authDomain": MY_AUTH_DOMAIN,
"projectId": MY_PROJECT_ID,
"credential": {
"credential_": {
...
}
}
}
}
}
This breaks my application while executing locally as expected configuration values cannot be retrieved.
Why is my configured "auth" object not contained in the result like it is when I invoke the other url endpoint?