react-firebase-starter
react-firebase-starter copied to clipboard
default Boilerplate error message
Hi,
i'm new to this, i would like to ask of this issue i'm facing after running yarn build and yarn start :
Error: Failed to parse private key: Error: Invalid PEM formatted message.
at FirebaseAppError.FirebaseError [as constructor] (/Users/zhenhaowu/code/freelance/TodoList/node_modules/firebase-admin/lib/utils/error.js:39:28)
at FirebaseAppError.PrefixedFirebaseError [as constructor] (/Users/zhenhaowu/code/freelance/TodoList/node_modules/firebase-admin/lib/utils/error.js:85:28)
at new FirebaseAppError (/Users/zhenhaowu/code/freelance/TodoList/node_modules/firebase-admin/lib/utils/error.js:119:28)
at new Certificate (/Users/zhenhaowu/code/freelance/TodoList/node_modules/firebase-admin/lib/auth/credential.js:129:19)
at new CertCredential (/Users/zhenhaowu/code/freelance/TodoList/node_modules/firebase-admin/lib/auth/credential.js:192:64)
at Object.cert (/Users/zhenhaowu/code/freelance/TodoList/node_modules/firebase-admin/lib/firebase-namespace.js:224:58)
at Object../src/app.node.js (/Users/zhenhaowu/code/freelance/TodoList/build/app.js:792:37)
at webpack_require (/Users/zhenhaowu/code/freelance/TodoList/build/app.js:645:30)
at /Users/zhenhaowu/code/freelance/TodoList/build/app.js:713:55
at Object.
You have to navigate to https://console.firebase.google.com/project/_/settings/serviceaccounts/adminsdk and create Private Key there.
Hey @DarkArtistry. Does @kudzuu answer solve your issue?
And then update FIREBASE_SERVICE_KEY
in .env
to the new private key. Make sure to have to put it all on one line, or else JSON parser wont work!
This should be added to the getting started
@Jakobovski you can create pull-request <)
i will try it out and let you guys know !
what is the .env
variable supposed to be? in the project there is GCP_SERVICE_KEY
which is in the shape of a firebase generated key. In the console I get the same error for this issue: Warning, FIREBASE_CONFIG environment variable is missing. Initializing firebase-admin will fail
, then @Jakobovski says FIREBASE_SERVICE_KEY
. If I grep the project the only one of these that shows up outside of .env
is here https://github.com/kriasoft/react-firebase-starter/blob/master/src/server/index.js#L21
I tried to follow the boilerplate instructions and added all the env vars to .env.local, including GCP_SERVICE_KEY with a key from Firebase put on one line without spaces. The two things I notice messing up are the error in the console about missing FIREBASE_CONFIG and the routes /admin/users
and /admin/stories
render blank pages (when logged in to the app with a couple existing users and stories).
Edit: I got past some of the error messages by configuring the deploy and getting that to work. But the admin pages (/admin/users and /admin/stories) are still blank. Looking at the react code those are just setup to render children but it's not clear that children are passed in anywhere. Do those pages ever work or are they like a starting point example that isn't supposed to render anything yet?
Edit: more digging, found that the migration defaults to creating users with is_admin: false. If I override this to be true, either in the migration or in the resolver, the admin pages are still blank.
+1
+1 to learn more about gcp_service_key, including the format expected for app.jwt_secret="xxxxx" in
$ firebase --project=example-prod functions:config:set \
app.app_origin="https://example.com" \
app.gcp_service_key="xxxxx" \
app.gcp_server_key="xxxxx" \
app.jwt_secret="xxxxx" \
app.google_client_id="xxxxx" \
app.google_client_secret="xxxxx" \
app.facebook_app_id="xxxxx" \
app.facebook_app_secret="xxxxx" \
app.pgdatabase="xxxxx" \
app.password="xxxxx"
@greg234234 @rojobuffalo I don't see any problem in getting this app. running. You can download whole json config from firebase console and place it under app. directory.
Your key inside your .env
must be wrapped inside a single and double qoutes in the same time like this
'"[PRIVATE_KEY]"'
which indeed the same format you will get from heroku when you call this command $ heroku config:get PRIVATE_KEY -s >> .env
One more thing to add to JSON.parse
in case it stills gets you an error which you will find in here:
https://stackoverflow.com/questions/50299329/node-js-firebase-service-account-private-key-wont-parse
So after you came back from that page, the final code line will look like this:
JSON.parse(process.env.PRIVATE_KEY).replace(/\\n/g, '\n')