In you App.js you aren't setting the same auth state as you do in you Login component. It seems that you have missunderstood the concept of context a bit. Or there are some important bits of code missing here. You need to create a "AuthProvider" that stores your context. And you can handle the login and the "check auth cookie" request in that Provider instead of doing it in different parts of the app.
I can't really point you in the right correction based on this. I recommend reading kentcdodds.com/blog/authentication... to get some understanding of how it can be done.
Is your app.get("/login", ...) function only returning what got passed in req.session.user or have you stripped out some logic there?
Also this useEffect needs to have authState.status in its dependency array like this:
In you App.js you aren't setting the same auth state as you do in you Login component. It seems that you have missunderstood the concept of context a bit. Or there are some important bits of code missing here. You need to create a "AuthProvider" that stores your context. And you can handle the login and the "check auth cookie" request in that Provider instead of doing it in different parts of the app.
I can't really point you in the right correction based on this. I recommend reading kentcdodds.com/blog/authentication... to get some understanding of how it can be done.
Is your
app.get("/login", ...)function only returning what got passed inreq.session.useror have you stripped out some logic there?Also this useEffect needs to have authState.status in its dependency array like this:
otherwise it will only check that status on initial render. You can read about it here reactjs.org/docs/hooks-reference.h...
Yess. I already have an AuthContext.Provider in App.js and I imported it
app.get is just returning req.session.user. I created it in app.post('/login'). Here it is
Thank you for the tips and the sources. I will check immediately