Closed sagargulati closed 1 year ago
Actually you are using the old pages directory.
You can't just use it like this. Only environment variables prefixed with NEXT_PUBLIC_
are going to be exposed.
You need to either use the app dir or one of the old ways of data fetching like getServersideProps
We have an example for the appdir here which worked fine: https://docs.upstash.com/redis/quickstarts/nextjs13
Even though I have UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN in my .env.development
file.
I also tried to rename the file to .env
and I still get the same error.
If I use the code console.log(process.env.UPSTASH_REDIS_REST_URL)
, it does fetch the value and shows them in the console.
Also, NEXT_PUBLIC
usually exposes the data publically and shows tokens and keys to the people, which we usually don't want!
We use /pages/
directory, and we also tried /src/pages
. Any suggestion we can make it work without the apps
directory?
Thanks!
Yes as I mentioned above, please use either getServersideProps
, getStaticPropsor
getInitialProps` to load the data.
you can not use the Redis client in the frontend without exposing the token
Greetings,
I'm on Next.js 13 created using
npx create-next-app
Packages
index.jsx
.env.development
The Error
Tried & Failed
Seems to work with passed as STATIC!
Even though I have UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN in my
.env.development
file. I also tried to rename the file to.env
and I still get the same error.If I use the code
console.log(process.env.UPSTASH_REDIS_REST_URL)
, it does fetch the value and shows them in the console.Can you suggest what could be wrong?
Thanks!