Skip to content

[question] createClient not able to run without 'NEXT_PUBLIC' environment variables #2522

@mdzialo00

Description

@mdzialo00

Hi,
I'm currently integrating Sanity into my Next.js project, and I noticed something I’d like to clarify. When using createClient, I expected to be able to do:

const sanityClient = createClient({ projectId: process.env.SANITY_PROJECT_ID })

However, it only works if I use:
const sanityClient = createClient({ projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID })

This effectively exposes the projectId to the client side. I understand that it's not considered sensitive information, but I’d still prefer to avoid making it publicly accessible if possible. Without the NEXT_PUBLIC prefix, I get the following error:

Image

Is it just because of how this library is designed, and it's working on the client side if it requires NEXT_PUBLIC exposed variables?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions