Ranushka kalhara
Ranushka kalhara

Reputation: 63

How to store sensitive data in react js frontend?

I want to clear this issue. I'm new to react js. but I need to store some sensitive data in frontend. just like database name, database password, and database username. I have used universal-cookie and local storage also. but it seems like not secure. because anyone can edit that data if they inspect the page and open the cookie tab. I just want to know if there is a way to make these cookies uneditable or suggest to me if there is a better way to keep this data in frontend?

Thanks in advance

i have edited the access token and dbname for testing

Upvotes: 4

Views: 5356

Answers (2)

Nowfal
Nowfal

Reputation: 26

Normally, sensitive data is not saved on the frontend. The best approach is to fetch this data from the server using an HTTP request. Alternatively, you can use local storage, cookies, session storage, etc. Another option is to set up environment variables. Additionally, you can use third-party storage solutions, as many free and trusted resources are available.

Upvotes: 1

ssaquif
ssaquif

Reputation: 330

Ideally you do not want to, you should always send it encrypted from your BE> But if you must you can create a .env.local file at the root of your react project and put all your variables there. The variable names should start REACT_APP. there should be NO space/quotations around your values in this file

REACT_APP_DB_PASS=your_pass
REACT_APP_DB_ID=your_id

and then you can access them from the process.env object like this

process.env.REACT_APP_DB_PASS

Upvotes: 1

Related Questions