How do I output the config of a firebase project and save it into a .json file via the Firebase CLI? I have a Firebase web project using React and it has both prod and staging environments and I want a way to configure my project automatically so that I can simply run firebase use [project]
and then firebase deploy
without having to worry about the correct config. This is what was working for me before the newish version of the Firebase CLI:
I'd run firebase setup:web --json > ./src/firebase-config.json
in my package.json and then read from the config during initializeApp
. But now, setup:web
is deprecated and no longer works. So you're supposed to use apps:sdkconfig web [project-id]
instead, but I can't get it to work like I did before. If I downgrade firebase-tools, I can get it to work again the old way.
In the new setup (using
apps:sdkconfig
), you must pass the project id and I'd like a way to auto pass this (i.e. it should know the project I switched to viafirebase use
).And the second issue, is that even when testing this by passing my current project id explicitly, I'm getting scope errors:
[debug] [2020-05-09T16:18:57.519Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
[debug] [2020-05-09T16:18:57.519Z] > authorizing via signed-in user
[debug] [2020-05-09T16:18:57.526Z] > refreshing access token with scopes: ["email","https://www.googleapis.com/auth/cloud-platform","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","openid"]
[debug] [2020-05-09T16:18:57.527Z] >>> HTTP REQUEST POST https://www.googleapis.com/oauth2/v3/token
<request body omitted>
[debug] [2020-05-09T16:18:57.722Z] <<< HTTP RESPONSE 200 {"content-type":"application/json; charset=utf-8","vary":"X-Origin, Referer, Origin,Accept-Encoding","date":"Sat, 09 May 2020 16:18:57 GMT","server":"scaffolding on HTTPServer2","cache-control":"private","x-xss-protection":"0","x-frame-options":"SAMEORIGIN","x-content-type-options":"nosniff","alt-svc":"h3-27=\":443\"; ma=2592000,h3-25=\":443\"; ma=2592000,h3-Q050=\":443\"; ma=2592000,h3-Q049=\":443\"; ma=2592000,h3-Q048=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\"","accept-ranges":"none","transfer-encoding":"chunked"}
[debug] [2020-05-09T16:18:57.738Z] >>> HTTP REQUEST GET https://firebase.googleapis.com/v1beta1/projects/-/webApps/[projectId]/config
[debug] [2020-05-09T16:18:57.969Z] <<< HTTP RESPONSE 400 {"vary":"X-Origin, Referer, Origin,Accept-Encoding","content-type":"application/json; charset=UTF-8","date":"Sat, 09 May 2020 16:18:57 GMT","server":"ESF","cache-control":"private","x-xss-protection":"0","x-frame-options":"SAMEORIGIN","x-content-type-options":"nosniff","alt-svc":"h3-27=\":443\"; ma=2592000,h3-25=\":443\"; ma=2592000,h3-Q050=\":443\"; ma=2592000,h3-Q049=\":443\"; ma=2592000,h3-Q048=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\"","accept-ranges":"none","transfer-encoding":"chunked"}
[debug] [2020-05-09T16:18:57.969Z] <<< HTTP RESPONSE BODY {"error":{"code":400,"message":"Request contains an invalid argument.","status":"INVALID_ARGUMENT"}}
[debug] [2020-05-09T16:18:57.972Z] HTTP Error: 400, Request contains an invalid argument.
[debug] [2020-05-09T16:18:57.975Z] FirebaseError: HTTP Error: 400, Request contains an invalid argument.
Anyone have a nice way to switch configuration in their Firebase React projects? Here is the full info on the old way I used to do it: https://stackoverflow.com/a/59592541/2946924