My demo site is built with Svelte/Sapper and uses the npm google-spreadsheet to connect to Google Sheets. https://gbps.netlify.app/
The Google Sheets API provides a credentials.json file for authentication. I’ve created a Netlify function that references the credentials JSON file like so:
await doc.useServiceAccountAuth(require('./credentials.json'));
I’m deploying from my Git repo, but I don’t want my credentials.json file to be in the repo. Is it possible to upload my credentials file to my functions folder without putting it in my repo?
Some more info…
My preferred method was to put all of my credentials in Environment Variables through the Netlify UI…
…and reference them in my function like so:
const clientSecret = { "type": "service_account", "project_id": process.env.PROJECT_ID, "private_key_id": process.env.PRIVATE_KEY_ID, "private_key": process.env.PRIVATE_KEY, "client_email": process.env.CLIENT_EMAIL, "client_id": process.env.CLIENT_ID, "auth_uri": "https://accounts.google.com/o/oauth2/auth", "token_uri": "https://oauth2.googleapis.com/token", "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", "client_x509_cert_url": process.env.CLIENT_X509_CERT_URL }; await doc.useServiceAccountAuth(clientSecret);
But for some reason, that always fails on build. (Never the first time for some reason, but on all subsequent builds.)
When I make the credentials.json file external again, it builds without issues. (Again, never the first time, but on all subsequent builds.)
After days of trying everything I can think of to make it work with env vars, I’m (for now) resigned to leaving my credentials.json file external.
I’d greatly appreciate any suggestions on how to use my credentials file without having to keep it in my repo, or even suggestions on what I may be doing wrong with environment variables (I’m happy to provide more code).
Thanks!