0

I have setted this env variable in my .env file and i want to save a value later. I'm using React.

REACT_APP_ID_USERLOGGED=""

Then i have this fragment of code that would have to save an id.

process.env.REACT_APP_ID_USERLOGGED = res.config.data

But if a do it, i receive this error Uncaught SyntaxError: invalid assignment left-hand side So, which is the correct way to do that or how can i solve it?

EDIT: I'm trying to save the id into REACT_APP_ID_USERLOGGED from a React Component, not into the .env file.

  • How are you handling the .env file? This may have already been answered here https://stackoverflow.com/questions/52888214/how-to-set-environment-variable-in-react-js – Max Jun 28 '21 at 18:13
  • I'm handling it fine i think, if i set an env variable with a value in the .env file just like: `REACT_APP_ID_USERLOGGED=value` and then print it on terminal it shows well, no errors appears. On the other hand, i saw the link and i believe that i can't apply nothing useful. Thanks anyways. – Gabriel Caramés Jun 28 '21 at 19:24
  • If your intention is to save whether the user is logged in, may i know why you want to save it to the environment variable? You could utilize localstorage to store this type of data. Or you have some specific requirement for this? – RABI Jun 30 '21 at 07:32
  • Yeah, you right. I have investigated about localStorage and that's what i needed. Thank you! – Gabriel Caramés Jun 30 '21 at 12:46

1 Answers1

0

In the end i have done this issue from the user Id with LocalStorage, without .env file or environment variables.

By the way, i still dont understand why my process.env.REACT_APP_ID_USERLOGGED = res.config.data dont work and gives me an error. If anybody could answer this it will be great.