In my app I want to allow a user who returns to my app to be automatically forwarded to a dashboard if a cookie is already saved and valid. Valid means that, if the cookie exists, an API will check if the token from the cookie is existing.
If existing (valid), a user would be forwarded to a dashboard, a restricted route. If not, the user would be redirected to login.
Theory is fine. Now here’s the issue: though working with componentDidMount it’s not working as I want. I get back that the result is wrong - not authenticated - and doesn’t forward. Then the request is loading successfully, but nothing happens. Now the problem is that it’s hard to find a tutorial really covering this issue that helps.
I’d like to provide the following example in a CodeSandbox so you can see what I’ve created so far.