Replies: 17 comments 37 replies
|
Hi, thanks! Following the example app, can you confirm you're double-quoting the env var ( In your local environment, you might also try hardcoding the private key in the config. Of course, do not add that to source control. |
|
I struggled with this for a while, none of the proposed solutions were working for me. I ended up Base64 encoding the private key, and then decoding it when initializing |
|
just went through this for about an hour, found what I was doing wrong.
|
|
For anyone still having troubles, i had replied to a previous comment but it might not be seen.
|
|
I have also been working on this for an hour! Providing some more detail here in case it helps others. My main problem was not restarting my local server after updating the .env.local file. This is working for me: .env.local - the key is double quoted initAuth.js This library looks like a great solution overall! |
|
I ran into this issue and am deploying my application on Kubernetes via GKE. Posting my solution in case anyone else struggles in the future.. I saved the private key in a No changes needed in my Note that I do set initial values in my Dockerfile to avoid any To debug quickly on K8s, I recommend accessing the pod via |
|
For anyone else running into this error. After trying to replace the I was able to make it work by simply getting rid of the last |
|
I had a problem that when I stringify my private key it was turning /n in //n. In my .env I changed all of the //n back to /n so the env entry looks like:
A few things to note, the entire key needs wrapped in single ' not the normal double " and the \n must remain a \n not a \n in the private key. then when I use the key:
|
|
For heroku config vars
|
|
Anyone faced this issue after resolving the parsing issue? and I'm trying to read it like this Im using heroku stack 22. Everything works well in localhost |
|
How do you guys pass either String or undefined there? for me it complains that privateKey can only be string
|
|
What worked for me is on vercel environment variable. |
|
Testing for a React app deployed on Vercel, I've had the same parsing problem with the FIREBASE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\nMIIE...XtQ\n-----END PRIVATE KEY-----\n"And this is my fix const env = process.env;
// FIX: Add auto-removed parts
let PrivateKey = "-----BEGIN PRIVATE KEY-----\n" + (env.FIREBASE_PRIVATE_KEY || "").replace(/\\n/g, "\n") + "\n-----END PRIVATE KEY-----\n";
try {
admin.initializeApp({
credential: admin.credential.cert({
projectId: env.FIREBASE_PROJECT_ID,
privateKey: PrivateKey,
clientEmail: env.FIREBASE_CLIENT_EMAIL,
}),
});
} catch (error) {
console.error("Error initializing Firebase:", error);
} |
|
As of April 25, 2025, when adding your Firebase private key manually to Vercel, the simplest and most reliable solution is: More complex solutions still work, but this is the cleanest and most up-to-date method. |







Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi there,
Thanks for creating this great plugin!
I have been attempting to setup my firebase configuration and have had quite some trouble. I've followed the example (initAuth.js & .env.local) as best as possible, however I run into an error upon authenticating through firebase.
I see this error client side: uncaught (in promise) Error: Received 500 response from login API endpoint: {"error":"Unexpected error."}
And server side I've logged out the error: error in login.js: FirebaseAppError: Failed to parse private key: Error: Invalid PEM formatted message.
I've also read through the issue thread that seems to be related but can't figure out exactly what I've done wrong. Any help would be greatly appreciated!
Thank you!
All reactions