Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Can you use an environment variable in the preview function?

default discord avatar
mauz.2 years ago
2

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

process.env

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

  • default discord avatar
    notchr2 years ago
    @195510103758209025

    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:
    
    PAYLOAD_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_XXXXXXXXXXXXXXXXXX
    
    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.


    https://payloadcms.com/docs/admin/webpack#admin-environment-vars
  • default discord avatar
    mauz.2 years ago

    Thanks a lot!

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.