Can you use an environment variable in the preview function?

default discord avatar
2 months ago

I mean, from console logging, I can see that the function is actually executed on the client, not the server, so


is not really available. Is there any other option to pass that variable?

  • default discord avatar
    2 months ago

    @mauz. I could be wrong, but I believe you can prefix env vars with PUBLIC, or some keyword that allows it to be available for the client

    I would check the official doc on this, I forget it off the top of my head

    Payload will automatically supply any present env variables that are prefixed with PAYLOAD_PUBLIC_ directly to the Admin panel.
    For example, if you've got the following environment variable:
    This key will automatically be made available to the Payload bundle and can be referenced in your Admin component code as process.env.PAYLOAD_PUBLIC_STRIPE_PUBLISHABLE_KEY.
  • default discord avatar
    2 months ago

    Thanks a lot!

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!


Connect with the Payload Community on Discord



Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.