React beginner here and to SPAs in general. I'm trying to make my login state persistent across my app but I struggle with when the user refreshes the page. Currently I have a method in my login form that calls the server to login and I guess receives a cookie (I'm using Flask with the Flask-Login extension). So I thought a simple thing which I've seen in a couple examples is to store the loggedIn
state in my parent <App>
component like this:
constructor() {
super();
this.state = {
loggedIn: false
}
}
logIn = () => {
this.setState({
loggedIn: true
});
};
And then pass the loggedIn
state and the logIn()
callback down to the login form. This works fine, but after refresh the loggedIn
state is false
again, obviously. Is using the way to do it? If so, how?
Thanks for your help.
EDIT: After a bunch of research I realized that Flask-Login is (obviously) a server-side session authentication scheme or whatever. So the cookie it sends is httpOnly
, so I can't access it using JS as recommended in the first answer. Is there any documentation out there using httpOnly
session cookies in SPAs?