I have setup an express REST API backend , React Front End . When user launches front end app , it will be redirecting user to signin page using oauth and express server creates session id after successful authentication. I could see a browser cookie connect.sid.
In my react app i have a private route which i defined to check user is not logged in or not before dashboard or user profile page. But i am not sure what check i can do to validate user session.
<Route path='/' exact component={Home} />
<Route path='/login' component={Login} />
<Route path='/register' component={Register} />
<PrivateRoute authed={this.props.isSessionActive} path='/dashboard' component={Dashboard} />
<PrivateRoute authed={this.props.isSessionActive} path='/user-profile' component={UserProfile} />
One solution i can think of is calling in my redux action e.g. isSessionActive call express REST API and check for req.isAuthenticate() on REST API middleware. I am not sure if calling the API before each page navigation is a good idea.