Replies: 2 comments 7 replies
-
|
Is the key something like: |
Beta Was this translation helpful? Give feedback.
-
|
The error The likely bug in your fix: the common suggestion is const privateKey = process.env.GOOGLE_PRIVATE_KEY.replace(/\\n/g, '\n');Note the double backslash: Steps that work reliably on Vercel:
const auth = new google.auth.GoogleAuth({
credentials: {
client_email: process.env.GOOGLE_CLIENT_EMAIL,
private_key: process.env.GOOGLE_PRIVATE_KEY.replace(/\\n/g, '\n'),
},
scopes: ['https://www.googleapis.com/auth/spreadsheets'],
});
Alternative (bulletproof) approach — base64: If the dashboard keeps mangling it, sidestep the problem entirely: # locally, encode the key
node -e "console.log(Buffer.from(process.env.GOOGLE_PRIVATE_KEY).toString('base64'))"Store the base64 string in Vercel as const privateKey = Buffer.from(process.env.GOOGLE_PRIVATE_KEY_B64, 'base64').toString('utf8');Base64 is a single line with no special characters, so nothing can corrupt it. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I am trying to deploy a Next js app on Vercel that has a google sheets integration. The two environment variables I need in order for it to work are the client_email and the private_key from google. However, after inputting them on the vercel env variables dashboard my api just gives this error

I have tried many different formats for the private key but none remove the error. Some common suggestions I've seen are calling the var with a replace(/\n/g, '\n') at the end, but that doesnt seem to change anything. All of it works on localhost though including the env vars inside a .env.local file getting called by process.env.VAR
Beta Was this translation helpful? Give feedback.
All reactions