DEV Community

Discussion on: How to Store a Long, Multi-line Private Key in an Environment Variable

Collapse
 
lukfcsl profile image
Lucas Farias

Fixed it removing the single quotes wrapping the string.
It's all working perfect now, thank you!!!

Collapse
 
inezabonte profile image
Ineza Bonté Grévy • Edited

Still facing the issue
JSON.parse: unexpected character at line 1 column 1 of the JSON data

My key is in the .env.local file

FIREBASE_PRIVATE_KEY={"privateKey":"-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQE...-----END PRIVATE KEY-----"}
Enter fullscreen mode Exit fullscreen mode

and I'm retrieving it like this

const { privateKey } = JSON.parse(process.env.FIREBASE_PRIVATE_KEY);
Enter fullscreen mode Exit fullscreen mode