I have implemented passportjs session based authen...
# random
e
I have implemented passportjs session based authentication and I am able to store session in mongodb but in react router I am able to navigate to private routes if I navigate through history.push() but if I change url directly and reload then I am directly logged out and redux loggedIn state is reset how can I avoid this scenario?
In my case connect.sid which is a cookie is stored in browser when user logins but if I refresh page then redux state is reset and due to which user is navigated to login again
c
Referch user object using cookie?
Do an API call to fetch the user object, shouldn't be too difficult. Show a loader in the meanwhile
e
@crooked-tent-69024 In passportJs once login is successful passport.autheticate('local') will get executed which will attach passport object to req object i.e passport object will have userId. Now I in /auth route I am checking if req.isAuthenticated() is true or not which means checking if user session exists in DB or not but in my case req.isAuthenticated is always false for other routes except login any idea why so? code: https://gist.github.com/aditodkar/0e07ec552c2912d33dd18977f3a75fbd
If I want to integrate this react auth code https://kentcdodds.com/blog/authentication-in-react-applications/ with passportJS session based auth then will I need to create additional endpoint which will check if current session is valid or not and based on that return true/false in json response from server and then set the state in react is this correct approach?