Learn how to securely manage and use secrets in your React modules for authentication and API access.
hs secrets add
command in the HubSpot CLI:
secretNames
array in your cms-assets.json
config:
theme.json
configuration using the secret_names
property:
secretNames
(camelCase) while themes use secret_names
(snake_case).getSecret()
function from @hubspot/cms-components
:
getSecret()
can only be called from component code executed on the server and not from the browser (i.e. within an island). The most secure pattern is using secrets in getServerSideProps
as shown above, since this ensures secret-handling code never reaches the client bundle.
getSecret()
has important security restrictions:
getServerSideProps
getServerSideProps
rather than directly in component code, as this ensures secret-handling logic never reaches the client bundle.
If you need to pass a secret value to client-side code (which makes it publicly viewable), you must explicitly pass it via an island prop:
@hubspot/cms-dev-server
, create a .env
file in your project root to define secret values for local use only.
Keys in this file need to be prefixed with HS_
to be recognized by the dev server as secrets:
HS_
prefix. In the example above, you can access them with:
.env
file is only for local development. Never commit this file to version control as it may contain sensitive information.