I have a question regarding session cookies in React.
Currently this is how I authenticate a user:
export function loginUser({ email, password }) {
return function(dispatch) {
axios.post(`${API_URL}/users/authenticate`, { email, password }, { withCredentials: true })
.then((response) => {
if (response.data.result_status == "success") {
localStorage.setItem("token", JSON.stringify(response.data.user))
dispatch({ type: AUTHENTICATE_USER });
browserHistory.push("/home");
})
}
})
.catch(() => {
dispatch(authError('Incorrect Login Info'));
});
}
}
I send the email and password to a url. If the response.data.result_status == "success", then I set the user info (like their name and email) to a localStorage token and I call AUTHENTICATE_USER which sets another localStorage item to true.
Since I'm using localStorage, the data persists when I reload. And as long as the authenticated localStorage is not set to null, I stay on the system.
However, now we want to stay on the system as LONG as the cookie's session is not expired. Currently I stay on the system based on the token I set to local storage, not the cookie.
The backend is not using JWT, just a cookie. Is there a way for me to check if the cookie is still in session with axios?
${API_URL}/users/authenticatethat set the session cookie ?