In my project, I'm using the nodeJS and react. For the session on the backend side, I'm using the httpOnly cookie. So when the user login, we're sending the httpOnly cookie with JWT token (httpOnly cookie contains JWT token). Now using this httpOnly cookie, I'm checking the authentication on the backend side.
Now, the problem is how to manage the session (or do authentication check) on react side? because here, we can't access the httpOnly cookie using the javascript.
For example:
- /login route --> httpOnly cookie send to the user
- /dashboard ----> Suppose, the user wants to open it route without login then we first need to check whether the user is valid or not (If we use local storage then it would be easy because we only need to check the token store in local storage). Now how to check the authenticity of the user in the cookie?
It would be great help if anyone has any idea to resolve this problem.