I am using MERN framework for building a simple yet a bit complex ecommerce app.
I will keep updating the below list for the technologies or libraries I will be requiring during making of this project
1.) The biggest challenge till now I face was how to make know the app that the user is logged in
because when I used redux the state was becoming true after logged in but as I refresh the page the is Logged state in store gets reset bcoz of which my conditional rendering in react is changing
for that I simply made a authCheck endpoint and called it inside the useEffect which solved my problem
2.) when I log in I get navigated to home page which works fine but if I go back then my login page is still exposed
To solve this I just used the global logged in state and conditional render the login page
3.) Since the redux is not able to persist the state after reload
to know the user or admin is logged in
we have several ways to solve this
Local Storage
1.) storing the authToken in loaclstorage and using useEffect to check the token still exists in the loacl stoarge
Local storage is a persistent storage which data is availabe on all domains
2.) We can use the redux-persist library to remember the state
3.) Web Socket and socket IO can be used (I need to learn more about it)
4.) Using jugaad to keep persisting the state throughout application
More about 4.) on Login the isAuth becomes true
after then when i go to any route for eg user dashboard there is a useEffect which dispatch fetch product some function and also dispatch the isAuth state to be true becoz of which the state is always true
hence persisiting the state*****
4.) When i try to set the option of select quantity of a product in the user dashboard then all the associated select statement of the products also get set.
Google is blocking the third party cookie reading and setting because of CSRF(cross site request forgery)
when user req /login endpoint
The server stores the cred in db and sends a token inside the cookie as a response to the browser where it is stored
Now user req /cart endpoint (Now cookie is automatically send with the request )
The server first verifies the jwt token inside the cookie and then sends the cart json data to user as response.
Now if the backend cookie setting is sameSite none and no domain is mentioned cors is not configured then hacker.com can make request to backend.com/cart and pretend as a user
or if the backend cookie setting is sameSite none and domain is frontend.com and cors is also frontend
then CSRF attacks can still occur if attackers can trick users into visiting malicious webpages that make cross-origin requests to your backend. To mitigate this risk, additional protections such as CSRF tokens or Double Submit Cookie patterns should be implemented on the frontend to verify the origin of requests and prevent unauthorized actions.
Comments
Post a Comment