๐Ÿ”ฎ Sanity Create is here. Writing is reinvented. Try now, no developer setup

Is there a Better Way to Pass My ProjectId and Dataset in a Secure Way?

2 replies
Last updated: Apr 24, 2020
Is there a better way to pass my projectId and dataset in a secure way to my code? This is using block-content-to-react.
    <PortableText blocks={post._rawDescription} projectId={"abc123"} dataset={"myCoolDataset"} />
Apr 24, 2020, 2:30 PM
You could create a config-file with environment variables, which is imported into this file, and spread it.config.js (copied from my gatsby project)

module.exports = {
  sanity: {
    projectId: process.env.GATSBY_SANITY_PROJECT_ID || 'default',
    dataset: process.env.GATSBY_SANITY_DATASET || 'production'
and then in your Portable text file:

import clientConfig from 'client-config';


<PortableText {...clientConfig} .../>
Apr 24, 2020, 2:38 PM
Just keep in mind that project IDs and datasets are not considered "secret". You probably want to make sure they are easy to replace if you want to switch to a different dataset, for instance, but the security shouldn't be in not knowing those IDs ๐Ÿ™‚
Apr 24, 2020, 8:16 PM

Sanityโ€“ build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?