Next.js Discord

Discord Forum

Why my front can't access to .env ?

Answered
Awakno posted this in #help-forum
Open in Discord
Avatar
Hi, I want to create a Admin Page for my website, but when I do a condition to check if good email, process.env.admin_mail return undefined ?

Anyone know why ?
Image
Answered by B33fb0n3
you can't access your serverside only env variables on the clientside.

You can create a .env file and add your public variable there with NEXT_PUBLIC_YOUR_ENV=12345. After that you are able to access it on the clientside
View full answer

3 Replies

Avatar
@Awakno Hi, I want to create a Admin Page for my website, but when I do a condition to check if good email, process.env.admin_mail return undefined ? Anyone know why ?
Avatar
you can't access your serverside only env variables on the clientside.

You can create a .env file and add your public variable there with NEXT_PUBLIC_YOUR_ENV=12345. After that you are able to access it on the clientside
Answer
Avatar
Oh ok thx
Avatar
happy to help