iron-session icon indicating copy to clipboard operation
iron-session copied to clipboard

Will this work with an external server using express-session?

Open daniellin215 opened this issue 3 years ago • 0 comments

Hi, I have a external express server using express-session.

In my next.js app, I call a login route and the server returns a cookie in the response header. Then I do a router.push(/to-protected-route). And in my protected-route page, I do the following but I see that the request fires twice and on the server it sees 2 cookies with 2 different sids. I was wondering does iron-session help with the problem I am having? Thanks!:

export const getServerSideProps: GetServerSideProps = async (context) => { const cookies = context.req.cookies; if (cookies["connect.sid"]) { console.log("calling getUser"); const data = await graphqlRequestClient.request(GET_ME, undefined, { cookies: context.req.cookies.toString(), }); console.log("data", data); } else { return { redirect: { destination: "/login", permanent: false, }, }; } return { props: {}, // will be passed to the page component as props }; };

daniellin215 avatar Feb 08 '22 15:02 daniellin215