iron-session
iron-session copied to clipboard
Will this work with an external server using express-session?
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 sid
s. 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 }; };