pls how do I prevent my API key from being exposed,
I'm using next.js and i have my .env file like this: NEXT_PUBLIC_MOVIEDB_APIKEY=KEY, and i read it well in the application but in production,
I want to hide it in my repo. I'm using vercel for that.
in my gitignore file the .env is included but once its in production it doesn't work anymore.
Can't find a movie or TV show? Login to create it.
Want to rate or add this item to a list?
Not a member?
Reply by ticao2 š§š· pt-BR
on May 12, 2023 at 8:26 AM
I think that by adding some keywords to the title of this conversation, maybe other users will more easily understand the problem and can help.
Hide API Key - Vercel Next.js ,env file
Reply by lwinkk
on May 4, 2024 at 8:11 PM
add the environment variable to your vercel dashboard so vercel has access to it in prod as well. it will work fine in dev env since youre reading everything straight from sourc code. but vercel doesnt have access to github files that are ignored. .env file is ignored so you need to explicitly tell vercel what the key is. this is a generic rule and applies to any host that is deploying your github code.