0

I am trying to make my login re-usable by storing enviromental variables in .env.local. However whenever I try to call these variables I get undefined.

here is my .env.local file

REACT_APP_AMARBIS_API_KEY = classified
REACT_APP_AMARBIS_AUTH_DOMAIN = classified
REACT_APP_AMARBIS_FIREBASE_PROJECT_ID = classified
REACT_APP_AMARBIS_STORAGE_BUCKET = classified
REACT_APP_AMARBIS_MESSAGING_SENDER_ID = classified
REACT_APP_AMARBIS_APP_ID = classified

and here is where I am trying to access them

import firebase from 'firebase/app'
import "firebase/auth"

const app = firebase.initializeApp({
    apiKey: process.env.REACT_APP_API_KEY,
    authDomain: process.env.REACT_APP_AMARBIS_AUTH_DOMAIN,
    projectId: process.env.REACT_APP_AMARBIS_FIREBASE_PROJECT_ID,
    storageBucket: process.env.REACT_APP_AMARBIS_STORAGE_BUCKET,
    messagingSenderId: process.env.REACT_APP_AMARBIS_MESSAGING_SENDER_ID,
    appId: process.env.REACT_APP_AMARBIS_APP_ID
})

export const auth = app.auth()
export default app
3
  • I asume you're using dotenv npm package? Commented Jan 10, 2021 at 23:43
  • Yes I used create react app then even just tried installing it manually later. Commented Jan 10, 2021 at 23:43
  • 1
    sometimes you have to restart your app manually specially when using enviroment variables Commented Jan 10, 2021 at 23:46

2 Answers 2

3

You'll need to stop your development server and re-run it using npm start. Each time you update your .env file, you'd need to do this, else you'll get undefined when you try to use the environment variables in your project

Sign up to request clarification or add additional context in comments.

1 Comment

I figured that out right before I saw this. Thanks a ton this was the solution.
0

So I think the problem was that I couldnt change these during a run and all references to them had to be set during startup.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.