kriasoft / react-firebase-starter

Boilerplate (seed) project for creating web apps with React.js, GraphQL.js and Relay
https://firebase.reactstarter.com
MIT License
4.51k stars 754 forks source link

default Boilerplate error message #301

Open DarkArtistry opened 6 years ago

DarkArtistry commented 6 years ago

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. (/Users/zhenhaowu/code/freelance/TodoList/build/app.js:716:10) at Module._compile (internal/modules/cjs/loader.js:654:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10) at Module.load (internal/modules/cjs/loader.js:566:32) at tryModuleLoad (internal/modules/cjs/loader.js:506:12) at Function.Module._load (internal/modules/cjs/loader.js:498:3) at Module.require (internal/modules/cjs/loader.js:598:17)

kudzuu commented 6 years ago

You have to navigate to https://console.firebase.google.com/project/_/settings/serviceaccounts/adminsdk and create Private Key there.

andrewkslv commented 6 years ago

Hey @DarkArtistry. Does @kudzuu answer solve your issue?

Jakobovski commented 6 years ago

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!

Jakobovski commented 6 years ago

This should be added to the getting started

kudzuu commented 6 years ago

@Jakobovski you can create pull-request <)

DarkArtistry commented 6 years ago

i will try it out and let you guys know !

ryanblakeley commented 5 years ago

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.

johndevor commented 5 years ago

+1

signalprime commented 5 years ago

+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"
kudzuu commented 4 years ago

@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.

mahmoudZakaria90 commented 4 years ago

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')