React and Env Variables when using Vercel KV

I am using react as the framework, also using Vercel KV to retrieve some values from session storage.

React only allows you to use the env variables as “REACT_APP_” prefix. When doing this for REACT_APP_KV_REST_API_URL and REACT_APP_KV_REST_API_TOKEN, it returns an error “Error: @vercel/kv: Missing required environment variables KV_REST_API_URL and KV_REST_API_TOKEN” I am guessing that it is expecting the value as KV_REST_API_URL and KV_REST_API_TOKEN, has someone encoutered this issue?

Hey @iaaaaan96! Prefixed environment variables are not provided by default to help protect your database. You should generally avoid exposing database credentials in client-side code.

I would recommend using @vercel/kv in a serverless function. Then you can fetch data from the serverless function in your client-side code.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.