I am new to React but somehow I have managed to develop a MERN (Mongoose, Express, React, Node) app. The back-end stores the data into the Mongo database. It sends and receives API to the front-end with the user data. I am receiving user data from the back-end who have already registered and storing it into a global hook so that it can be shared by all the components.
What I want to achieve is to be able to render components based on whether the user is logged in or not. I need something like JWT with local storage or a cookie but not sure how to start. The user information should presists even when the app is refreshed. Can someone suggest how I can achieve this?
Also, I am using react-router-dom ^6. I have realized that there are some differences in the previous versions.
Thanks in advance!