jamilharun / LAB1-FINALS

0 stars 0 forks source link

Dotenv is undefined for some reason #3

Open jamilharun opened 7 months ago

jamilharun commented 7 months ago

Branch

dotenv_undefined

issue 2

Dotenv is undefined for some reason.

i created .env to securely store important secrets and keys for our future api calls but something wrong. it wouldnt output. it just says its undefined and causing whole app to crash

.env

SECRET_KEY = sdf7g697fdg76dfjkgh
API_KEY = .com.DF09F94JL67DF67

App.jsx

<p>
          Edit <code>src/App.jsx</code> and save to test HMR
          {process.env.SECRET_KEY}
          {process.env.API_KEY}
</p>
jamilharun commented 7 months ago

fix

base on the documentation of vite-react

1. you should install the .env modules

npm install dotenv

2 the .env variable should all start with the:

"VITE" letter.

changing the current "SECRET_KEY" will turn into "VITE-SECRET_KEY" and other "VITE_API_KEY"

VITE-SECRET_KEY
VITE_API_KEY

3 then to call the value of each variable in the .env

i need to change the current "process.env.SECRET_KEY" and "process.env.API_KEY" into "import.meta.env.VITE-SECRET_KEY" and "import.meta.env.VITE_API_KEY"

import.meta.env.VITE-SECRET_KEY
import.meta.env.VITE_API_KEY