I understand similar questions has been asked here, here and in a hundred other questions posts. So I will make sure to focus on the missing parts in these posts.
I have a create-react-app running on same server with a node express server with a cors configuration of:
app.use(
cors({
origin: "http://localhost:3000",
credentials: true,
})
);
I would make a get request in this way:
Axios.get("http://localhost:8080/base/hasemail", { withCredentials: true })
.then(result => {
console.log( "Has Email?",result.data)
this.setState({
hasEmail: result.data
})
})
}
req.user returns the user as long as I got the { withCredentials: true }
in the GET request.
However in the POST request, same can't be said:
Axios({
method: "POST",
data: {
son: 137URR,
},
withCredentials: true,
url: 'http://localhost:8080/addsvj'
})
I know JWT need to be implemented especially when client is on a different server. I don't have JWT implemented. Could this be the cause of req.user being undefined POST requests?
Any idea what else I am doing wrong?