Comments (6)
Managed to resolve in the end. I had made it far more complicated than needed
Resolution was to add all of the JSON key into a single parameter in .env and then use JSON.parse to put into the object.
// .env
GSA_AUTH_KEY={"type": "service_account","project_id": "xxxxx","private_key_id":"xxxxxxx" etc etc}
// gatsby-config.js
require("dotenv").config({
path: `.env`,
})
var GSAobj = JSON.parse(process.env.GSA_API_KEY)
....
{
resolve: 'gatsby-source-google-sheets',
options: {
spreadsheetId: 'get this from the sheet url',
worksheetTitle: 'ie the name in the worksheet tab',
credentials: GSAobj,
}
},
I then added the same single line parameter in Netlify UI and I have this working both locally and on Netlify (whilst retaining privacy of the key with .env included in .gitignore). Thanks to @krerkkiat for helping me in the right direction. Hope this helps someone else!
from gatsby-source-google-sheets.
@d1sc0 - thanks so much for this - saved me a tonne of googling! Clear instructions and worked like a dream.
from gatsby-source-google-sheets.
Maybe this is what you are looking for?
https://www.gatsbyjs.org/docs/environment-variables/#server-side-nodejs
from gatsby-source-google-sheets.
yes this is what I was trying to achieve but the docs for this plugin show configuration for this plugin as follows in gatsby-config.js
credentials: require('./path-to-credentials-file.json')
As the json file referenced holds multiple parameters I was unsure how I could make this work with .env variables which seem to be always referenced as individual options in all examples I could find. Sorry I might just be missing something obvious.
from gatsby-source-google-sheets.
It seems that require()
will give back an object, so you can still use the method described in the link to load the information and then manually rebuild the object. It would be something like
// .env
SERVICE_ACCOUNT_TYPE=service_account
SERVICE_ACCOUNT_PROJECT_ID=id
SERVICE_ACCOUNT_PRIVATE_KEY_ID=key
SERVICE_ACCOUNT_PRIVATE_KEY=key
SERVICE_ACCOUNT_CLIENT_EMAIL=email
SERVICE_ACCOUNT_CLIENT_ID=id
SERVICE_ACCOUNT_AUTH_URI=uri
SERVICE_ACCOUNT_TOKEN_URI=uri
SERVICE_ACCOUNT_AUTH_PROVIDER_X509_CERT_URL=url
SERVICE_ACCOUNT_CLIENT_X509_CERT_URL=url
// gatsby-config.js
require("dotenv").config({
path: `.env`,
})
var cred = {
"type": process.env.SERVICE_ACCOUNT_TYPE,
"project_id": process.env.SERVICE_ACCOUNT_PROJECT_ID,
"private_key_id": process.env.SERVICE_ACCOUNT_PRIVATE_KEY_ID,
"private_key": process.env.SERVICE_ACCOUNT_PRIVATE_KEY,
"client_email": process.env.SERVICE_ACCOUNT_CLIENT_EMAIL,
"client_id": process.env.SERVICE_ACCOUNT_CLIENT_ID,
"auth_uri": process.env.SERVICE_ACCOUNT_AUTH_URI,
"token_uri": process.env.SERVICE_ACCOUNT_TOKEN_URI,
"auth_provider_x509_cert_url": process.env.SERVICE_ACCOUNT_AUTH_PROVIDER_X509_CERT_URL,
"client_x509_cert_url": process.env.SERVICE_ACCOUNT_CLIENT_X509_CERT_URL
}
....
{
resolve: 'gatsby-source-google-sheets',
options: {
spreadsheetId: 'get this from the sheet url',
worksheetTitle: 'ie the name in the worksheet tab',
credentials: cred
}
},
from gatsby-source-google-sheets.
Thank you SOO Much. This has got it working well locally.
Problem I have now is when deployed to Netlify it fails to build - I've tried setting these values in the nelify UI environment variables but it does't seem to want to work
from gatsby-source-google-sheets.
Related Issues (20)
- How do I query from the plugin? HOT 1
- Documentation updates HOT 9
- Changes to the g-sheet data is not reflected in graphiql query result HOT 1
- Accessing client_secret.json HOT 3
- Warnings when installing version "^1.1.1" HOT 2
- error thrown during sourceNode lifecycle: "TypeError: value must be an array of bytes"
- Unable to fetch email field as graphql data from google sheet instead getting 0 as value
- Naming the first column of a sheet "id" breaks the plugin HOT 2
- Error with worksheets HOT 3
- Will Google Sheets API v4 break this plugin? HOT 1
- New to Gatsby, how can I access data? HOT 1
- Mixed field types HOT 2
- How does this perform with super large spreadsheets?
- value must be an array of bytes on uuid
- Upgrade to new Google API version before January 26, 2021
- What happens with bold/italic text? HOT 1
- Cannot read property 'createNode' of undefined (boundActionCreators.createNode) - GatsbyJS 3.2.1 HOT 7
- TypeError: Cannot read property 'worksheets' of undefined HOT 15
- Maintenance? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gatsby-source-google-sheets.