axios icon indicating copy to clipboard operation
axios copied to clipboard

Can not send cookie back from client, tried many ways

Open namnguyen2091 opened this issue 3 years ago • 0 comments

Summary

I'm new user from nodejs (expressjs) and axios too and I have a problem. I set cookie from nodejs server with:

app.use(cors({
	origin: 'http://localhost:2000'
	credentials: true
}));
res.cookie('refresh_token', refresh_token, {
      maxAge: 30 * 24 * 60 * 60 * 1000,
      httpOnly: true,
      sameSite: 'strict'
});

I can see response cookie from browser but in storage I can not see. I use res.header do the same, nothing happen. httpOnly: false does not work. And in client I try:

const instance = axios.create({
	withCredentials: true,
	baseURL: 'http://127.0.0.1:5000',
	headers: {'Access-Control-Allow-Origin': '*', 'Content-Type': 'application/json'},
	credentials: 'include',
})
instance.post(
	'/users/def/refresh_token', 
	{"access_token":"ABC"}
)

I can not find other ways to do this, every result I got in google do this but I dont know why that not working for me. With Postman it automatic send cookie every request. Please help me!

Environment

  • API: http://localhost:5000
  • Front end: http://localhost:2000
  • Axios Version: 0.27.2
  • Browser: Chrome 101.0.4951.64 (Official Build) (64-bit)
  • Node.js Version: v12.13.0
  • OS: Ubuntu 20.4
  • Additional Library Versions: Reactjs 17.0.2

namnguyen2091 avatar Aug 09 '22 07:08 namnguyen2091