DEV Community

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

Collapse
 
lukfcsl profile image
Lucas Farias • Edited

Hi Claudio, thank you for the post!
I'm still facing an issue, where the variable is not being read correctly from the environments variables set through Vercel's UI.
I'm getting:

Build error occurred
20:28:41.478    SyntaxError: Unexpected token ' in JSON at position 0
20:28:41.478        at JSON.parse (<anonymous>)
20:28:41.478        at Module.23aj (/vercel/workpath0/.next/serverless/pag
Enter fullscreen mode Exit fullscreen mode

this is because the key is undefined or sort of

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