im just trying to look for an explanation here. so i have a front end using Next and backend with Express and i want them to exchange cookies. ive read several topics regarding these and found 2 supposedly working methods, however only 2 of the methods worked for me.
these are the settings for Express (note i use the library cookie-parser)
app.use(cors( {origin: 'http://localhost:3000',credentials: true}))
and now the issue comes with attaching cookies in my requests from Next with Axios. the working solution for me that i got was attaching the cookies manually in the request like so.
export async function getServerSideProps(context) {
const res = await axios.get("/contact/get-all",{ withCredentials: true, headers: {
Cookie: context.req.headers.cookie
}, });
const data = await res.data
// const data = context.req.headers
// Pass data to the page via props
return { props: { data } }
}
now another solution that people said to have worked is to include credentials like
withCredentials: true
or
axios.defaults.withCredentials = true
but in my express when i try to get the cookies with this method
req.cookies
it returns null. why is this? am i missing something?