apologies in advance for what seems like a repeat question.
I've tried lots of other stack overflow and other solutions and cant seem to see what I'm doing wrong.
I'm trying to send and set a cookie from my express server to my front end so that it can be sent back with each request to authenticate. This is working in insomnia and on the 9090 host but when I push it up to the proper server it just stops working and wont set the cookie at all.
all the headers are showing up
I'm also getting no errors in the console so no help there.
react example of request
export const logIn = (formInput) => {
return listApi.post(`/users/authenticate`, formInput, {withCredentials:true})
.then( ({ data }) => {
return data
})
express
app.use(cors({
origin: "http://192.xxx.x.xx:xxxx",
credentials: true,
origin: true
}));
res.status(200)
.header('Access-Control-Allow-Credentials', true)
.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept')
.header("Access-Control-Allow-Origin", "http://192.168.1.69:3000")
.header("Access-Control-Allow-Methods", "GET,POST,PATCH,PUT,DELETE,OPTIONS")
.cookie('access_token', token, {expires:tokenExpire,
sameSite: 'None',
secure: true,
httpOnly: true,
Domain: 'http://192.168.1.69:3000'})
.send({ msg: 'success' });
} else {
Promise.reject( {status: 401, msg: 'unauthorized - invalid username and password'})
.catch(err => next(err))
}
};
EDIT: here are the things I've read so far
res.cookie not setting cookie in browser
Express-Session not working in production/deployment
Express-session cookie not saving in browser
Cookies on localhost with explicit domain
https://www.reddit.com/r/reactjs/comments/vxvdib/cookie_not_being_set_in_react_app_express_backend/